Regular Expressions 101

Community Patterns

jaswsinc: The second trickiest regex pattern I've ever written

1

Regular Expression
PCRE (PHP <7.3)

/
(?P<open_dsq>(?<!\\)["\'])(?P<dsq_value>(?s:\\.|(?!\\|(?P=open_dsq)).)*?)(?P<close_dsq>(?P=open_dsq))
/
g

Description

Notice that I had to find this ​_anywhere_​ in the string, unlimited times, and account for escaped quotes.

Submitted by Jason Caldwell - 9 years ago