-1

I need a RegEx that matches the following:

(whatever)   3.4  Temp
(whatever)   7.8  Name
(whatever)  10.0  Other Name

Basically, it has to match whatever in the beginning, and then either two spaces, two digits, a dot and a digit or three spaces, one digit, a dot, and a digit, followed by two spaces and whatever.

This is easily matched with this RegEx:

.*?  [\s|\d]\d\.\d  .*?

However, I want to extract the decimal number and whatever's after it using a backreference. I was trying

.*?  [\s(\d\.\d)|(\d\d\.\d)]  (.*?)

However, referring to it with \1,\2 doesn't work, I think because the parentheses I'm referring to are in the optional square brackets with the '|' symbol. Is there a solution?

Alex Beals
  • 1,965
  • 4
  • 18
  • 26

1 Answers1

1

Sure, just pull the space out of the character class.

.*?\s+([\d.]+)

However since \d is literally [0123456789.], just drop the character class. And since .*? will match those leading spaces too, drop the \s too!

.*?(\d+)
Adam Smith
  • 52,157
  • 12
  • 73
  • 112