Skip to content

Instantly share code, notes, and snippets.

@cubespace
Forked from igorpronin/php, regexp
Created May 30, 2017 08:56
Show Gist options
  • Save cubespace/19ed1fed8ae400fb3a9c84fbb2236a95 to your computer and use it in GitHub Desktop.
Save cubespace/19ed1fed8ae400fb3a9c84fbb2236a95 to your computer and use it in GitHub Desktop.
Возврат подстроки, которая начинается с определенной строки и заканчивается определенной строкой без их включения в результат, preg_match
$str = 'the result inside big string';
preg_match("/(?<=the )(.*)(?= inside)/", $str, $result_arr);
echo $result_arr[0]; // result
/*
(?<=) - с чего начинается искомая строка
(?=) - чем заканчивается искомая строка
(.*) - искомая строка содержит любое количество любых символов
PS: хороший конструктор регулярных выражений - http://www.phpliveregex.com/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment