RSS
 

Minus als gültiges Zeichen in Regex

16 Apr

Wenn man ein Minuszeichen als solches in einem regulären Ausdruck angeben will, gibt PHP gerne den REG_ERANGE-Fehler aus, obwohl der Ausdruck richtig (escaped) zu sein scheint. Einen Workaround fand ich hier, nämlich das Setzen des Hyphens ans Ende der Zeichenfolge.

Beispiel:

Eigentlich richtig, funktioniert aber nicht:
^([a-zA-Z0-9\-= ]{5,50})$

Korrektur, Minus als letztes Zeichen:
^([a-zA-Z0-9= -]{5,50})$

 
No Comments

Posted in PHP

 

Leave a Reply

 

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word