你好,我需要匹配端(從右到左)。例如一個字符串從字符串hello999hello888hello 最後我需要得到最後一組hello
和last
。其中間從下面的代碼正確工作。正則表達式從最終匹配
$game = "hello999hello888hello777last";
preg_match('/hello(\d+)last$/', $game, $match);
print_r($match);
但是,相反的777,我有符號號碼和字母的混合物,假設例如從字符串hello999hello888hello0string#@[email protected]#anysymbols%@iwantlast
我需要0string#@[email protected]#anysymbols%@iwant
。
$game = "hello999hello888hello0string#@[email protected]#anysymbols%@iwantlast";
preg_match('/hello(.*?)last$/', $game, $match);
print_r($match);
這是爲什麼上面的代碼returing 999hello888hello0string#@[email protected]#%#$%#$%#$%@iwant
何爲從右到讀取到左其他然後串反向方法的正確步驟。
注:我想用preg_match_all aswel.for例如
$string = 'hello999hello888hello0string#@[email protected]#anysymbols%@iwantlast
hello999hello888hello02ndstring%@iwantlast';
preg_match_all('/.*hello(.*?)last$/', $string, $match);
print_r($match);
它必須返回0string#@[email protected]#anysymbols%@iwant
和02ndstring%@iwant
提示:*是貪婪的,這意味着它_eats_儘可能它可以在一個匹配的正則表達式中 – Jost
爲什麼你這樣拆分字符串?在我看來,這是一個XY問題:http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem –