Regex替换所有前导">"只有一个“&;&;&;”

regex to replace all leading ">" with only one ">"

本文关键字:quot 有一个 替换 Regex      更新时间:2023-09-26

如何用一个>来匹配和替换所有前导>

我尝试使用^>(.*?)[^'W]+,但这似乎并不适用于所有情况。

一些可能的情况:

>> >> > some matching <string> goes in here >...
>   > >
>   > >'n
>

应该看起来像

> some matching <string> goes in here >...
>
>
>

我想你在找

/^[>'t ]+/

替换为"> "

这个怎么样?

/>[>'s]+/g
http://jsfiddle.net/kS9ny/

只影响leading…添加^或删除g

/^>[>'s]+/
http://jsfiddle.net/kS9ny/2/

str.replace(/^('s*>'s*)+/gm, '> ');

试试这个

str.replace(/^>[>'s]*/gm, '>')

请尝试这个模式,它应该能达到你想要的效果:

/(>'s*)+/
相关文章: