2

Will all browsers (IE6+, FF3+, Safari 3+, Chrome) execute a javascript regex search across line boundaries in the searched string? Example:

var sourceStr = "This is some text \nOn multiple lines\nAnd the 2nd line.";
sourceStr = sourceStr.replace(/line/g, "xxx");

Also, are there any good references of what regex features are or aren't supported in various browsers.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Some problems with IE, at least: http://www.bennadel.com/blog/1917-Javascript-Multiline-Regular-Expressions-Don-t-Include-Carriage-Returns-In-IE.htm – Dan Rosenstark Jul 04 '11 at 05:52
  • 1
    have you tried on those browsers? – Ibu Jul 04 '11 at 05:53
  • I don't have easy access to all those browsers right now (particularly the older ones), so I'm asking for the experiences of others. The reason I ask is that I have a faint memory that there was some sort of multi-line regex issue with IE, but I don't recall if it was this issue or something else. – jfriend00 Jul 04 '11 at 05:56
  • Here is a very good tool to test your code on all IE versions: [IE Tester](http://www.my-debugbar.com/wiki/IETester/HomePage) – Ibu Jul 04 '11 at 05:58

2 Answers2

4

Yes, but if you use any char syntax - dot "." in regex patterns, you may need to change it to [\s\S] to match any chars across lines.

YOU
  • 120,166
  • 34
  • 186
  • 219
1

The ECMA specification (ECMA-262) dictates acceptable regular expression grammar and multiline support is explicitly mentioned. Section 15.10.2.6 in particular demonstrates the effect of multiline support on Assertions.

So, if the browser supports the ECMA-262 specification, then yes, it supports multiline.

Of course, you should endeavor to test your code before you can be confident it works. It wouldn't be the first time a browser has failed to implement a specification correctly.

EDIT: To clarify, JavaScript 1.5 is fully compatible with ECMA-262, Edition 3. I understand the following browsers support JavaScript version 1.5 or higher:

  • Safari 2.0 or newer (Mac)
  • Camino 0.8 or newer (Mac)
  • Firefox 0.9 or newer (Windows, Mac, Linux)
  • Internet Explorer 6.0 or newer (Windows)
  • Mozilla 1.2 or newer (Linux)
  • Netscape 7.1 or newer (Windows, Mac)
  • Opera 8.0 or newer (Windows, Mac, Linux)

Can't actually find a decent source for Chrome although I'd be shocked if it didn't support JavaScript >= 1.5.

hoipolloi
  • 7,984
  • 2
  • 27
  • 28
  • I won't downvote this, but the OP was asking about specific browsers, and you're answering about a spec. Unless you mention which browsers are compliant with the spec, it's not really an answer, IMO. – Dan Rosenstark Jul 04 '11 at 06:13