Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Does Safari support JavaScript RegExp?

In a cross-browser test of RegExp, Safari seemed to not support it.

MacBook Pro, OS X Mavericks (10.9.1)

Posted on Sep 5, 2016 6:40 PM

Reply
2 replies

Sep 6, 2016 7:13 AM in response to WCHawk

The answer is yes, Safari has supported JavaScript RegExp for years. It is straight forward when used in HTML. If you use RegExp in a Do JavaScript within AppleScript, it invokes an Apple Event, and Safari 9.1.3 will block you with the following dialog:

User uploaded file

One then enables Allow JavaScript from Apple Events from the Safari Develop menu, at the cost of a user password prompt when the AppleScript is run.


Look at the Regular Expressions example for JavaScript at Rosetta Code. Add that to a <script> section in an HTML document, and add the following line before your closing </script> tag, before you open the HTML in Safari 9.1.3.


alert(isMatch + " " + matches[1]);

Does Safari support JavaScript RegExp?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.