0

I have for example a string \try Tester234 where I want to find the Word (partially with digits) (RegEx => (\w|\d)) after the \try. But a var_dump($match) outputs that:

array
  0 => 
    array
      empty
  1 => 
    array
      empty

preg_match_all('/^\\try ((\d|\w)*)/i', "\try Tester", $match);

What am I doing wrong?

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
Poru
  • 8,254
  • 22
  • 65
  • 89

1 Answers1

1

You need four backslashes to insert a literal one in a regular expression:

preg_match_all('/^\\\\block ((\d|\w)*)/i', "\block Tester", $match);

which is maybe better written like this:

preg_match_all('/^\\\\block (\w+)/i', "\block Tester", $match);
Matteo Riva
  • 24,728
  • 12
  • 72
  • 104