php - PCRE pattern that matches the in-delimiters text of a PCRE pattern -


i'm looking pcre pattern match text in between delimiters of any valid pcre pattern regardless of delimiters , modifiers used.

there 4 paired delimiters, far know: (), [], {}, <>. other allowed characters used twice. according documentation, can use non-alphanumeric, non-whitespace, non-backslash character. pattern should work:

/ ^ (?=([^a-za-z0-9\s\\\\])) # make sure pattern begins valid delimiter                          # , capture group 1 (?|                      # alternation different delimiter types                          # each alternative captures pattern group 2   \((.*)\)               # handle (...) |   \[(.*)\]               # handle [...] |   \{(.*)\}               # handle {...} |   <(.*)>                 # handle <...> |   .(.*)\1                # handle other delimiters backreference ) [imsxeadsuxu]*           # allow modifiers $ /xs 

if use $pattern in

preg_match($pattern, $input, $matches); 

then you'll find desired result in $matches[2].

of course, accept bunch of invalid patterns, because not ensure delimiter not appear somewhere sooner in pattern.


Comments

Popular posts from this blog

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

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -