简体   繁体   中英

Match the start of each new line with JavaScript regex

I have a string with possible \\n in them. Think of:

 Foo1
  Foo2
Foo3  Foo4.

I want to replace   's at the start of each line, but the above is one string. ^nbsp; only matches the first   before 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

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