Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with:

Javascript Regular Expression (RegExp) Multiline Flag Not Universal

By Ben Nadel on

I was debugging some code and I just came accross a very interesting fact: the "m" flag for multiline searches in Regular Expression (RegExp) is not universal. It only works on newer browsers and not all of them for that matter. On this Javascript Site, it states that all searches work for multiline without the flag and that the "m" flag will indeed throw errors in older browsers (as I am finding in my debugging... stupid Mac IE).

So, to drive it home, this is not good:

  • new RegExp("[\\n\\r]+", "gim")

And should be replaced with:

  • new RegExp("[\\n\\r]+", "gi")

Both of these are searching for new line characters and returns across multiple lines; however, only the latter works in all browsers and is more "correct" for Javascript.




Reader Comments

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.