regex - How do I find the last occurrence of a match using regexp in MATLAB? -


if have following string in matlab:

str = '/* comment */ int x; /* sectionendexample */'; 

how find comment contains given string. in example, string 'sectionendexample'.

expr = ['^.*/\*.*sectionendexample.*\*/']; sectionendidx1 = regexp(str, expr); 

but returns sectionendidx1 1 means it's matching first '/' whereas want match last '/'.

i looking in documentation , have far played around lookaround options. however, can't figure out way in matlab :(

i not sure asking can edit regexp function return matches in cell array. , cell array, chose last index of it, last match.

sectionendidx1 = regexp(str, expr,'match'); 

this however, return entire string provided match, because based on criteria give regular expression, match entire string.

if not desired result, need modify regular expression string.

i suggest using website regexpal test regular expressions before plugging them matlab.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -