Regex match for first ending

I have a text like this sample. i want to match first "something" in my text. the "something" have any character in it, so i should use (.*) for it.

start: something, end ... blah blah ... start: something, end

I tried to match it like this:
start: (.*) end

but as you can expect this see last end in my text.

>Solution :

You just need to add a ? to your current regex:

start: (.*?) end

This will tell the .* to match lazily until the word "end".

Leave a Reply