开发者

PCRE match string between two brackets

开发者 https://www.devze.com 2023-02-01 05:58 出处:网络
in php I want to match the string: name if it was contained between (( )) I tried: /\\(\\((.*)\\)\\)/U and it works perfectly but if the string was between three brackets it fai开发者_StackOverflo

in php I want to match the string: name if it was contained between (( ))

I tried:

/\(\((.*)\)\)/U

and it works perfectly but if the string was between three brackets it fai开发者_StackOverflow中文版l so (((name))) or (((name)) doens't work

how to write a regexp for that?

Thanks a lot for your help


In a regular expression you can quantify the number of times something appears with {min,max} following the token. ie.

\({2,}(.*?)\){2,}

This matches 2 or more ( on the left and 2 or more ) on the right. Leaving the 2nd value of {min,max} blank means "min matches to infinite matches" so it will match ((((((((string))) or any variation as long as there are 2+ parens on each side.


\({2,}(.*?)\){2,}

Will match greater than 2 leading or trailing brackets.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号