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
to only affect leading... add a ^
or remove the g
/^>[>\s]+/
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.