Skip to content

Instantly share code, notes, and snippets.

@igorpronin
Last active May 30, 2017 08:56
Show Gist options
  • Save igorpronin/0da2bcd0bf87031c01c0c63d7b6ee9b7 to your computer and use it in GitHub Desktop.
Save igorpronin/0da2bcd0bf87031c01c0c63d7b6ee9b7 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