Reputation: 13
I have a string of digits that represent 3 different lenghts. I need to pick out the second length in the string but can't find away to exclude the white space from the match. Here is an example for the string. It has always 6 digits after the dot but before it vary. In this case it is 907.086614
that I need to match exactly.
1417.322835 907.086614 2.267717
^\s(\d+\.\d{6})
I've played around with different look behind but can't get it to exclude the white space.
Upvotes: 1
Views: 2512
Reputation: 829
You can try this
(?<=\s)(\d+\.\d{6})(?=\s)
see demo
But if you still want to use your pattern, remove the begin of line anchor ^
and match group 1
i.e
\s(\d+\.\d{6})
see demo
Upvotes: 0
Reputation: 104111
A potential side effect of \s
is that it matches carriage returns.
Since you are looking for the second column of a group of floats, it is better to be explicit:
\d[ \t](\d+\.\d+)[ \t]\d
^ trailing digit from first col
^ a single space or tab
^ ^ ^ capture float
^ single space or tab
^ leading digit of third col
You can also place the capture between a look ahead and lookbehind:
(?<=\d[ \t])(\d+\.\d+)(?=[ \t]\d)
Upvotes: 1
Reputation: 20024
How about with a positive look behind like:
(?<=\s)(\d+\.\d{6})
(?<=\s)
Positive Lookbehind - Assert that the regex below can be matches the \s
Upvotes: 0