Created
November 27, 2016 07:43
-
-
Save MasterHans/3b4f007e5e591f017308b8f5511291b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Описание регулиярных выражений: | |
* исходная строка'Hello, world! how are you?' | |
* . - любой символ | |
* .* - любой символ повторяющийся бесконечное число раз | |
* (.*) - захват подстроки в $1...$N | |
* i - не чувствительна к регистру -- '/hello,/i' | |
* [\s] - пробельный символ -- '/hello,[\s]/i' | |
* ^ - начало строки (якорь начала) -- '/^hello,[\s]/i' | |
* $ - конец строки -- '/hello$/i' | |
* [.,!] - идёт знак препинания из перечисленных -- '/you[.,!]$/i' | |
* word|world - в тексте идёт слово или word или world -- '/you[.,!]$/i' | |
* l? - l может быть а может не быть -- '/worl?d/i' | |
* l+ - l в произвольном количестве -- '/worl+d/i' | |
* w+ - символ составляющий слово в произвольном количестве -- '/\w+, \w+/i' | |
*/ | |
$str = 'Hello, world! how are you!'; | |
preg_match_all('/\w+, \w+/i',$str,$m); | |
var_dump($m); | |
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) { | |
echo "Match found!"; | |
} else { | |
echo "Match NOT found!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment