-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexp.php
31 lines (28 loc) · 1.06 KB
/
regexp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
echo preg_match('/Petr/', "Petr je borec") . PHP_EOL;
echo preg_match('/Petr/', "Je doma Petr?") . PHP_EOL;
echo preg_match('/Petr/', "Honza, Petr a Pavel") . PHP_EOL;
echo preg_match('/Petr/', "Franta je taky borec") . PHP_EOL;
function JeCeleCislo ($cislo)
{
return preg_match('/^[\+\-]?[\d]+$/', $cislo);
}
echo JeCeleCislo ("+1") . PHP_EOL;
echo JeCeleCislo ("-6") . PHP_EOL;
echo JeCeleCislo ("3.5") . PHP_EOL;
echo JeCeleCislo ("4 kusy") . PHP_EOL;
function JeEmail ($cislo)
{
return preg_match("/^[^@]+@[^@]+\.[^@]+$/",$cislo);
}
echo JeEmail ("[email protected]") . PHP_EOL;
echo JeEmail ("nekdo@@neco.cz") . PHP_EOL;
echo JeEmail ("nekdoneco.cz") . PHP_EOL;
echo JeEmail ("@neco.cz") . PHP_EOL;
echo JeEmail ("neco.cz") . PHP_EOL;
echo JeEmail ("nekdo@necocz") . PHP_EOL;
echo JeEmail ("nekdo@neco.") . PHP_EOL;
$retezec= "Mám řetězec se zbytečně mnoho mezerami, že ????";
echo $retezec . PHP_EOL;
echo preg_replace("/[[:blank:]]+/", " ", $retezec) . PHP_EOL;
echo preg_replace("/(z)(e)/", "$2$1", $retezec) . PHP_EOL; // exchange chars in pairS