Autor Zpráva
alfa47
Profil *
Ahojte,

mam takyto regularny vyraz:

preg_match('/.*([0-9]{3} ?[0-9]{2}) +([\p{L} ]+)[0-9]?.*/', '040 01 Trenčianske teplice 1', $matches);

a chcem ziskat PSC a mesto bez cisla.

Vsetko by fungovalo, ak by tam nebola diakritika. S nou sa to zasekne na tom makkceni. Som prezradny, pretoze \p{L} by to malo prave riesit.

Tusite prosim kde moze byt chyba?

Vopred dakujem velmi pekne.
juriad
Profil
echo preg_match('/.*([0-9]{3} ?[0-9]{2}) +([\p{L} ]+)[0-9]?.*/', '040 01 Trenčianske teplice 1', $matches);
var_dump($matches);
echo preg_match('/.*([0-9]{3} ?[0-9]{2}) +([\p{L} ]+)[0-9]?.*/u', '040 01 Trenčianske teplice 1', $matches);
var_dump($matches);
Přidej modifikátor u k regexu.
alfa47
Profil *
juriad:
Velka vdaka, takze ten modifikator znamena, ze to bere ako UTF-8 ano?
peta
Profil
http://cz1.php.net/manual/en/reference.pcre.pattern.modifiers.php

u (PCRE_UTF8)
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0