$array = ['GETST', 'GETT', 'GET', 'POST', 'GPOST', 'GEPOST', 'GETOST']; preg_grep('/GET|POST/', $array); All the specified array elements pass this regular expression. How to rewrite the regular season so that only GET and POST can pass?
$array = ['GETST', 'GETT', 'GET', 'POST', 'GPOST', 'GEPOST', 'GETOST']; preg_grep('/GET|POST/', $array); All the specified array elements pass this regular expression. How to rewrite the regular season so that only GET and POST can pass?
To limit matches in a pattern, you can use a sequence of characters \b...\b , denoting a word boundary , and not preserving brackets (?:...) :
$array = ['GETST', 'GETT', 'GET', 'POST', 'GPOST', 'GEPOST', 'GETOST']; $result = preg_grep('~\b(?:GE|POS)T\b~', $array); echo '<pre>', print_r($result, true), '</pre>'; Result:
Array ( [2] => GET [3] => POST ) Source: https://ru.stackoverflow.com/questions/765882/
All Articles
\b(GET|POST)\b- TimurVI