Search code examples
regexregular-language

Regular expression to replace shortest match


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.


Solution

  • You need to use non-greedy matching:

    start.*?end