Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

https://www.debuggex.com/r/qfeBXsBybijWDWbp

>Solution :

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

start: (.*?) end

https://www.debuggex.com/r/1VmZTRx0EqgNyH4Y

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading