Jump to content

Help matching all symbols except defined


Torrodon

Recommended Posts

When using a dash in a character class, put it as the first or last position (in this case, due to negation, the second or last position):

 

preg_match_all ( '/[^a-z0-9_ &-]/i' , $string , $matches );

 

Otherwise, regex will treat the mal-positioned dash as a range.. in your initial case, a range from space to & (which is not what you want).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.