2

I'm using Total Commander (file manager), which allows searching file content by regular expressions.

I'd like to search PHP files for deprecated syntax like $_SESSION[user] - so, I need the RegExp for finding all tags, which don't have quotes inside the square brackets.

Any ideas?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
Fuxi
  • 7,611
  • 25
  • 93
  • 139

1 Answers1

2

This is assuming you don't have defined constants:
\$\w+\[\s*(?:[a-zA-Z]+|[a-zA-Z]+(?:"|')|(?:"|')[a-zA-Z]+)\s*\]

Explanation:

  • \$ : match $
  • \w+ : match [a-zA-Z0-9_] one or more times
  • \[ : match [
  • \s* : match white spaces zero or more times
  • (?:[a-zA-Z]+|[a-zA-Z]+(?:"|')|(?:"|')[a-zA-Z]+) : match " or ' followed by letters, or just letters, or letters followed by ' or "
  • \s* : match white spaces zero or more times
  • \] : match ]

Online demo

Disclaimer: This will not validate your variables for example $0[aaa] would be matched.

HamZa
  • 14,671
  • 11
  • 54
  • 75