在PHP中,如何在一个以@(at)符号开头的单词后面直接删除所有双空格?
示例输入:
This is an @example input.
示例输出:
This is an @example output.
答案 0 :(得分:0)
匹配以@
开头的单词,重置匹配输出,然后匹配多个空格,然后进行替换:
preg_replace('~@\w+\K\s{2,}~', ' ', $input_string);
正则表达式解释:
@\w+ # Match a `@` fowlling a word
\K # Reset matching process output
\s{2,} # Match double or more whitespaces