Poru
Poru

Reputation: 8360

PHP: preg_match_all - Couldn't write a working RegEx

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?

Upvotes: 0

Views: 60

Answers (1)

Matteo Riva
Matteo Riva

Reputation: 25060

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);

Upvotes: 1

Related Questions