So I am scanning through chat logs looking for messages where I
mentioned “points”. My current regex is:
text.scan /^(.)([-+]?[0-9]+\s+points?)(.)$/i
So I’d like each match in 3 groups:
The message up until the part containing the points
The points part. This could have a + or - prefix, 1 or more digits,
and an optional s after point
The rest of the message line.
My problem is, the (.*) is eating up parts that I would like to appear
in group 2. I just bought a book on regex but I’m not very far yet
Any help would be appreciated!
My current regex is:
text.scan /^(.)([-+]?[0-9]+\s+points?)(.)$/i
[…]
My problem is, the (.*) is eating up parts that I would like to appear
in group 2.
Make it non-greedy: (.*?)
HTH,
Sebastian
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.