Sign in
Log inSign up

How to match regex of PHP variable with both brackets and parentheses, without and with dollar symbol in JavaScript?

Gustavo Benedito Costa's photo
Gustavo Benedito Costa
·Aug 17, 2018

I tried many times and it was successful. I am trying to solve the bug issue of the regex, which caused the PHP variables with brackets and parentheses not to be highlighted.

Here are two regexes:

  • /( \$)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
  • (\$)(\w+)\b

I want to match like:

  • $i
  • Si++
  • $p[$i]
  • $p[]
  • $p()

Without dollar symbol:

  • func_get_args()
  • func_num_args()
  • get_meta_tags()

You can view the "Regex Fiddle": regex101.com/r/DRinKf/2