Rombelirk
Rombelirk

Reputation: 11

How to use preg_match to search for symbols

How do i find matches with any of -+/* symbols using preg_match?

I try

$stroke = '21+64';
$pattern = '/[+-/*]/';

preg_match($pattern, $stroke, $matches);
var_dump($matches);

but it doesn't work.. Thank you.

Upvotes: 0

Views: 37

Answers (1)

arkascha
arkascha

Reputation: 42935

Have a try with that pattern:

/[+\-\*]/

You have to "escape" the - and the *, and you do that with a preceding "back slash" (\).

Upvotes: 1

Related Questions