我想转换这个字符串:
从"25马力"到"25马力"
和分别
"Foo bar 25 stack 1 overflow"至"Foo bar25 stack 1overflow"
在regex中有没有一种有效的方法可以做到这一点?
使用查找正则表达式:
$repl = preg_replace('/(?<='d)'h+(?=[a-zA-Z])/', '', $input);
RegEx演示
(?<='d) # assert that previous char is a digit
'h+ # match 1 or more horizontal space
(?=[a-zA-Z]) # assert that next char in an English letter