Alexander (HH): RegExp-Pattern so richtig? Wie kann man Fehler besser finden?

Beitrag lesen

Moin Moin!

http://www.php.net/manual/en/reference.pcre.pattern.syntax.php und dort verlinkte Seiten sollten hilfreich sein:

Wenn, dann wieder mit den eckigen Klammern. Weiß ich aber auch nicht, ob das eichtig ist.

/[1]$/

"The character types \d, \D, \s, \S, \w, and \W may also appear in a character class, and add the characters that they match to the class. For example, [\dABCDEF] matches any hexadecimal digit." -- hätte ich jetzt nicht gedacht, ist aber auch in Perl so.

Trotzdem matcht das Pattern nur, wenn der String exakt ein Zeichen lang ist, es fehlt ein "+" vor dem "$".

Wie schon erwähnt sind die Word Characters nicht notwendigerweise auf A-Za-z0-9_ beschränkt. "A 'word' character is any letter or digit or the underscore character, that is, any character which can be part of a Perl 'word'. The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the 'fr' (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w."

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so".

  1. \w- ↩︎