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

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -