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.
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.
Use replacement function with this regex /start.+?end/g
which will match the bold parts of your string. The g
part of the regex means globally, and might need to be implemented differently depending on the language you use.
The key here is to use ?
which turns on un-greedy matching. That means the match consumes the minimum amount of characters rather than the maximum, so will match from the start
to the next rather than the last end