Reputation: 93
here is my regexp:
/bar.*\d\sfoo/
input string:
bar something 1 foo bar something 2 foo bar
it's matches:
bar something 1 foo bar something 2 foo
instead of:
bar something 1 foo
bar something 2 foo
Is there way to solve this ?
Note: something is any characters, except new line.
Upvotes: 1
Views: 240
Reputation: 420951
You should make the *
reluctant, or lazy, by adding a ?
after it:
/bar.*?\d\sfoo/
Upvotes: 3
Reputation: 43235
You should use "lazy" operator "?" to match minimum of the pattern,else it matches till maximum match. Here is corrected version :
/bar.*?\d\sfoo/
See here : http://regexr.com?309sa
Upvotes: 0