Match start of every new line with JavaScript regex

I have a line with possible \n

in them. Think:

 Foo1
  Foo2
Foo3  Foo4.

      

I want to replace  

at the beginning of each line, but above is one line. ^nbsp;

matches only the first  

before Foo1

. I want to do at the beginning of any new line, look  

. Any ideas?

So, I want the regex to match the first two  

above, but not the third.

+3


source to share


1 answer


You need to enable multiline

flag match mode /m

to match each line as a separate line.



/^(?: )+/gm

      

+14


source







All Articles