Javascript Regular Expression (RegExp) Multiline Flag Not Universal

Posted May 11, 2006 at 8:18 AM

Tags: Javascript / DHTML

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:

 Launch code in new window » Download code as text file »

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

And should be replaced with:

 Launch code in new window » Download code as text file »

  • 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.

Download Code Snippet ZIP File

Comments (0)  |  Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Adobe ColdFusion 8.0.1 Update - Helping Programmers To Be Signifanctly Less Girlie - Download ColdFusion 8 Update 8.0.1 Now.

Reader Comments

There are no comments posted for this web log entry.


Post Comment  |  Ask Ben


Home   |   Web Log   |   ColdFusion   |   Projects   |   Resume   |   Job Form   |   Search   |   Contact
Epicenter Consulting - Custom Software Solutions for Business Evolution HostMySite.com - The Leader In ColdFusion Hosting