你好,我需要匹配端(从右到左)。例如一个字符串从字符串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 –