regex - PHP Regular expression to find string enclosed in __("STRING_TO_EXTRACT") -
sorry suck @ regexp. need collect string on application enclosed in example: __("string") string may enclosed in single quote well.
i tried following code:
$str = "__('match1') __("match2") do_not_include __('match3')"; preg_match_all("/__\(['\"](.*)['\"]\)/", $str, $matches); var_dump($matches);
but able match entire line string 1 match. example result below. please me edit regexp should able 3 matches.
match1') __("match2") do_not_include __('match3
thanks in advance help.
you can use:
$str = "__('match1') __(\"match2\") do_not_include __('match3')"; preg_match_all('/__\(([\'"])(.*?)\1\)/', $str, $matches); print_r($matches[2]);
([\'"])
match either single or double quote , capture in group #1.
.*?
match 0 or more characters (non-greedy)
\1
back-reference of above captured group make sure string closed same quote on rhs.
output:
array ( [0] => match1 [1] => match2 [2] => match3 )
Comments
Post a Comment