Regular expression to replace shortest match

Sai Mukesh picture Sai Mukesh · Feb 7, 2012 · Viewed 8.2k times · Source

my string is like this sfdfdsfdsfstart112matlab2336endgfdgdfgkknfkgstart558899enddfdsfd

how can we replace part of a string such a way that the result will be

sfdfdsfdsfgfdgdfgkknfkgdfdsfd

i.e bolded content need to be removed.

Answer

Mark Byers picture Mark Byers · Feb 7, 2012

You need to use non-greedy matching:

start.*?end