简体   繁体   中英

regex to replace all leading “>” with only one “>”

How do I make an expression to match and replace all leading > with only one >

I tried using ^>(.*?)[^\\W]+ but that doesn't seem to be working for all cases.

Some of the possible cases:

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

Should look like

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

I think you're looking for

/^[>\t ]+/

to replace with "> "

How about this one?

/>[>\s]+/g

http://jsfiddle.net/kS9ny/

to only affect leading... add a ^ or remove the g

/^>[>\s]+/

http://jsfiddle.net/kS9ny/2/

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

尝试这个

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

请尝试这种模式,它应该做您想要的:

/(>\s*)+/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM