Reputation: 455
Example string:
?token=a12b3c4d5e&time=1417111248&message=Lorem ipsum dolor sit amet.&mode=reply&bbcode=1&topic=123456789
Tried capturing the message with (?:\?|&)message=(.+)&
, however it matches everything until the last &
character:
Lorem ipsum dolor sit amet.&mode=reply&bbcode=1
How do I stop the capturing group when it encounters &
for the first time?
Expected result:
Lorem ipsum dolor sit amet.
Upvotes: 0
Views: 41
Reputation: 26667
You can use a very simple regex as
message=[^&]+
Example : http://regex101.com/r/rJ5qK2/1
[^&]+
matches anything other than a &
one or more timeOR
You can also use a non greedy .+?
as
message=(.+?)&
Example : http://regex101.com/r/rJ5qK2/2
Upvotes: 3