[英]Match the start of each new line with JavaScript regex
I have a string with possible \\n
in them.我有一个可能包含\\n
的字符串。 Think of:考虑到:
Foo1
Foo2
Foo3 Foo4.
I want to replace
我想更换
's at the start of each line, but the above is one string. 's 在每一行的开头,但上面是一个字符串。 ^nbsp;
only matches the first
只匹配第一个
before Foo1
.在Foo1
之前。 I want to do at the start of any newline, look for
我想在任何换行符的开头做,寻找
. . Any ideas?有任何想法吗?
So, I want a regex that'll match the first two
所以,我想要一个与前两个匹配的正则表达式
's above, but not the 3rd.上面,但不是第三个。
您需要使用/m
标志启用multiline
匹配模式,以便将每一行作为单独的行进行匹配。
/^(?: )+/gm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.