views:

30

answers:

1

Hello,

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?

+1  A: 

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);
kemp
Thanks, that's it.
Poru
`[\w\d]` makes no sense.
SilentGhost
@SilentGhost: indeed, forgot `\w` includes digits, thanks for pointing that out.
kemp