Reputation: 2866
The following regex matches any Unicode Letters + Unicode Numbers + Vowel Signs + Dot + Dash + Underscore + Space
/^[\w\pN\pL\pM .-]+$/u
Works successfully.
I want to edit my regex so it accepts the following:
? ! ( ) % @ # , + - : newline
-
represents negative sign.
My attempt doesn't work:
/^[\w\pN\pL\pM .-**?!()%@#,+-:\r**]+$/u
Here is my snippet with latest attempt:
if(preg_match('/^[\w\pN\pL\pM .-?!()%@#,+-:\r]+$/u', $_POST['txtarea_msg']))
Any idea?
Upvotes: 1
Views: 813
Reputation: 73031
Some of these are regular expression characters, so you need to escape them:
/^[\w\pN\pL\pM .?!()%@#,+\-:\r]+$/u
Also note the difference between a newline (\n
) and carriage return (\r
).
Upvotes: -1
Reputation: 360872
-
is a metacharacter in character classes, so you're saying:
blahblahblah all characters from .
to ?
blahblahblah all characters from +
to :
blah blah
It needs to be escaped with a \
: blahblah .\-? blahblah +\-: blahblah
Upvotes: 2