regex - Regular expression to get last occurence until next char -


i trying work out regular expression , stuck - can help.

i have string:

"this string [flag no match] should match [flag this] dont want [no no]"

i want capture last occurance of flag enclosed in brackets.

tried this:

\[flag(?!.*\[flag)(.*)\] 

i there, matches last "]" in string. how can match next "]" following match.

want match this: "this"

get this: "this] dont want [no no"

hope can help.

thanks

make * non-greedy,

\[flag(?!.*\[flag)(.*?)\] 

or

\[flag(?!.*\[flag)\s*([^\]]*)\] 

demo


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -