Regular Expressions 101

Save & share.

  • Regex Version: ver. 1
  • Fork Regex ctrl+s
  • Go to community entry
  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • .NET 7.0 (C#)
  • Regex Flavor Guide
  • Substitution
  • Unit Tests (20)
  • Code Generator
  • Regex Debugger
  • Export Matches

Explanation

Quick reference.

  • Common Tokens
  • General Tokens
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • A single character of: a, b or c [abc]
  • A character except: a, b or c [^abc]
  • A character in the range: a-z [a-z]
  • A character not in the range: a-z [^a-z]
  • A character in the range: a-z or A-Z [a-zA-Z]
  • Any single character .
  • Alternate - match either a or b a|b
  • Any whitespace character \s
  • Any non-whitespace character \S
  • Any digit \d
  • Any non-digit \D
  • Any word character \w
  • Any non-word character \W
  • Match everything enclosed (?:...)
  • Capture everything enclosed (...)
  • Zero or one of a a?
  • Zero or more of a a*
  • One or more of a a+
  • Exactly 3 of a a{3}
  • 3 or more of a a{3,}
  • Between 3 and 6 of a a{3,6}
  • Start of string ^
  • End of string $
  • A word boundary \b
  • Non-word boundary \B

Regular Expression

Apple’s Worldwide Developers Conference to kick off June 10 at 10 a.m. PDT with Keynote address

The Keynote will be available to stream on  apple.com , the Apple Developer app, the Apple TV app, and the Apple YouTube channel. On-demand playback will be available after the conclusion of the stream.

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

WCHawk

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

Loading page content

Page content loaded

Carolyn Samit

Sep 5, 2016 8:37 PM in response to WCHawk

VikingOSX

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]);

Workaround for Lookbehind Regex in Safari

Workaround for Lookbehind Regular expressions in Safari

Prathamesh Sonpatki

Prathamesh Sonpatki

In this post we will discuss:

  • What are Lookbehind Regex
  • Browser Compatibility of Lookbehind Regex
  • Alternative ways to use them so that it works in all browsers

What are Lookbehind regex

At times, we need to match a pattern only if it is followed or preceded by another pattern.

For eg. in case of URL which contains the organization information:

Here, :org is dynamic name of the organization which can be of following pattern:

We want to match all URLs which match the pattern for

But there are also URLs such as which we don't want to match.

Where the slug is also of same pattern as /[a-z0-9]/ .

So we want to make sure that we match the organizations URLs only if they are preceded by organizations word.

There is a way to write such regular expressions using Lookbehind regex which checks if a pattern is preceded by specific pattern.

The syntax is:

  • Positive lookbehind: (?<=Y)X , matches X , but only if there’s Y before it.
  • Negative lookbehind: (?<!Y)X , matches X , but only if there’s no Y before it.

In our case:

We use this as follows:

Which will basically replace anything that followed our pattern organizations/:org :

Browser Compatibility

Lookbehind regex are very powerful but they are not supported in all browsers. Non V8 browsers such as Safari don't support them.

Let's run the same example in Safari:

safari regex support

Alternative to use Lookbehind Regex in Safari

We can relook at our usage and try to avoid the lookbehind regex and just use the capture groups.

In this case, we capture two groups, the first one where organizations/:org/ gets captured and then in second everything else.

We want to keep organizations/:org/ and drop everything else. This can be achieved with following:

This basically keeps the first match and drops everything else. Most importantly, this works on Safari as well!

P.S. If you want detailed overview on Lookbehind and its friend Lookahead regex, this is an excellent post - https://javascript.info/regexp-lookahead-lookbehind

Sign up for more like this.

Flagrant Badassery

A JavaScript and regular expression centric blog

Safari Support with XRegExp 0.2.2

When I released XRegExp 0.2 several days ago, I hadn't yet tested in Safari or Swift. When I remembered to do this shortly afterwards, I found that both of those WebKit-based browsers didn't like it and often crashed when trying to use it! This was obviously a Very Bad Thing, but due to major time availability issues I wasn't able to get around to in-depth bug-shooting and testing until tonight.

It turns out that Safari's regex engine contains a bug which causes an error to be thrown when compiling a regex containing a character class ending with " [\\ ".

As a result, I've changed two instances of [^[\\] to [^\\[] and upped the version number to 0.2.2. XRegExp has now been tested and works without any known issues in all of the following browsers:

  • Internet Explorer 5.5 – 7
  • Firefox 2.0.0.4
  • Safari 3.0.2 beta for Windows

You can get the newest version here .

3 thoughts on “Safari Support with XRegExp 0.2.2”

I have now published my SweetXML parser, using your XRegExp.

I developed it first without using your code, and you will be pleased to here that it was a 5 minute swap-in. Worked a dream, with no errors.

SweetButty seems like the perfect kind of project to use XRegExp… a regex intensive app, which becomes much more self-documenting though named capture.

http://bugs.webkit.org/show_bug.cgi?id=14823

Leave a Reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Regex not compatible with safari, need help to convert

Hello guys, seems that Safari does not support look behind assertion, so now i have a perfect script that works fine except on Safari, there’s a way to make this perfectly cross-browser?

Use two regexes, one ran after the other.

it is not possible to use unique?

someone could provide an example? i have no experienxe with regex

this is the good work…but with no look behind for safari

It would be very helpful if you showed what you were trying to match. You can’t have lookbehind if you need to support Safari, but you can definitely use something different to match what you want. It’s difficult to know what though without knowing what your aim is.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.

  • | New Account
  • | Log In Remember [x]
  • | Forgot Password Login: [x]
  • Format For Printing
  •  -  XML
  •  -  Clone This Bug
  •  -  Top of page

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookbehind regexes don't work in Safari #10

@ronaldtse

ronaldtse commented Sep 1, 2020 • edited

@ronaldtse

ronaldtse commented Sep 1, 2020

Sorry, something went wrong.

@webdev778

webdev778 commented Sep 2, 2020

Webdev778 commented oct 23, 2020.

@webdev778

webdev778 commented Jul 9, 2021

Webdev778 commented jul 12, 2021, ronaldtse commented jul 12, 2021.

@xyzshantaram

xyzshantaram commented Sep 13, 2021

  • 👍 1 reaction

No branches or pull requests

@ronaldtse

JavaScript built-in: RegExp: test

  • 6 - 10 : Supported
  • 11 : Supported
  • 12 - 124 : Supported
  • 125 : Supported
  • 2 - 125 : Supported
  • 126 : Supported
  • 127 - 129 : Supported
  • 4 - 124 : Supported
  • 126 - 128 : Supported
  • 3.1 - 17.4 : Supported
  • 17.5 : Supported
  • 17.6 - TP : Supported
  • 10 - 109 : Supported
  • 110 : Supported

Safari on iOS

  • 3.2 - 17.4 : Supported
  • 17.6 : Supported
  • all : Support unknown

Android Browser

  • 2.1 - 4.3 : Not supported
  • 4.4 - 4.4.4 : Supported

Opera Mobile

  • 12 - 12.1 : Supported
  • 80 : Supported

Chrome for Android

Firefox for android, uc browser for android.

  • 15.5 : Support unknown

Samsung Internet

  • 4 - 24 : Supported
  • 25 : Supported
  • 14.9 : Support unknown

Baidu Browser

  • 13.52 : Support unknown

KaiOS Browser

  • 2.5 : Support unknown
  • 3 : Support unknown

Regex Tester

Substitution.

  • Results update in real-time as you type.
  • Roll over a match or expression for details.
  • Save & share expressions with others.
  • Explore the Library for help & examples.
  • Undo & Redo with {{getCtrlKey()}}-Z / Y.
  • Search for & rate Community patterns.

Regular Expression Javascript PCRE flags

Test string, safari test.

  • When asking a question, provide as much detail as possible. Posts of simply "It doesn't work" may be removed.
  • Be respectful
  • ` - Surround code with backticks
  • * - Surround text with stars to italicize.
  • > > - A line starting with two greater than characters will be indented as a quote.
  • A blank line will separate paragraphs.

Top Regular Expressions

Cheat sheet.

Regex Tester isn't optimized for mobile devices yet. You can still take a look, but it might be a bit quirky.

Regex Tester requires a modern browser. Please update your browser to the latest version and try again.

If you don't already have an account, Register Now

Join to access discussion forums and premium features of the site.

Please Share!

Regex for Safari 4+

  • 4.5 • 2 Ratings

Screenshots

Description.

Search web page using regular expression, copy all matched text with 1 click Highlight all matched text instantaneously on web page as you type. Automatic regex validation check as you type. In case you made a mistake composing your regex, input box will yield a red background so you know something is wrong right away. One click to copy all matched text on page. Keyboard shortcut support, "Command+Shift+F" to call the plugin, "Enter/Shift + Enter" to go to next/previous match. No need to type in regex every time. All your regular expressions are saved locally on your device. Customizable highlight color, among all the other options you can tweak to better suits your needs. Feedback and reviews are welcomed! Any questions, feel free to email me at [email protected]

Version 1.0.3

Improved extension popup page's load speed

Ratings and Reviews

Does the thing, but not gracefully.

First of all, the fact that this exists and is functional is excellent. 4 stars for showing up and working! There are a couple of areas that I would love to see improvement. First, the history should stay open if it was open for the previous page. It currently closes randomly. Second, there should be a way to rerun the previous search values on the next page visited. That would save loads of time.

Works Great

Very straightforward to use, makes searching on pages for complex things so much easier

App Privacy

The developer, 磊 高 , indicated that the app’s privacy practices may include handling of data as described below. For more information, see the developer’s privacy policy .

Data Not Collected

The developer does not collect any data from this app.

Privacy practices may vary, for example, based on the features you use or your age. Learn More

Information

  • App Support
  • Privacy Policy

safari regex support

Family Sharing

Up to six family members can use this app with family sharing enabled., you might also like.

Spatial Teleprompter

History Book - Browse & Search

Band setlist manager

Cisco Security Advisory

Cisco webex meetings meeting information and metadata issue june 2024, legal disclaimer.

THIS DOCUMENT IS PROVIDED ON AN "AS IS" BASIS AND DOES NOT IMPLY ANY KIND OF GUARANTEE OR WARRANTY, INCLUDING THE WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. YOUR USE OF THE INFORMATION ON THE DOCUMENT OR MATERIALS LINKED FROM THE DOCUMENT IS AT YOUR OWN RISK. CISCO RESERVES THE RIGHT TO CHANGE OR UPDATE THIS DOCUMENT AT ANY TIME. CISCO EXPECTS TO UPDATE THIS DOCUMENT AS NEW INFORMATION BECOMES AVAILABLE.

A standalone copy or paraphrase of the text of this document that omits the distribution URL is an uncontrolled copy and may lack important information or contain factual errors. The information in this document is intended for end users of Cisco products.

  • Leave additional feedback

Cisco Security Vulnerability Policy

To learn about Cisco security vulnerability disclosure policies and publications, see the Security Vulnerability Policy . This document also contains instructions for obtaining fixed software and receiving security vulnerability information from Cisco.

Subscribe to Cisco Security Notifications

Related to this advisory.

We've detected unusual activity from your computer network

To continue, please click the box below to let us know you're not a robot.

Why did this happen?

Please make sure your browser supports JavaScript and cookies and that you are not blocking them from loading. For more information you can review our Terms of Service and Cookie Policy .

For inquiries related to this message please contact our support team and provide the reference ID below.

COMMENTS

  1. Works in Chrome, but breaks in Safari: Invalid regular expression

    Looks like Safari doesn't support lookbehind yet (that is, your (?<=\/)). One alternative would be to put the / that comes before in a non-captured group, and then extract only the first group (the content after the / and before the # ).

  2. Lookbehind in JS regular expressions

    Lookbehind in JS regular expressions. The positive lookbehind ( (?<= )) and negative lookbehind ( (?<! )) zero-width assertions in JavaScript regular expressions can be used to ensure a pattern is preceded by another pattern. "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile ...

  3. Regex

    You can use a Regex to search for a pattern in a string or substring. Call contains(_:) to check for the presence of a pattern, or firstMatch(of:) or matches(of:) to find matches. When you find a match, the resulting Regex.Match type includes an output property that contains the matched substring along with any captures: When you import the ...

  4. regex101: Modern Safari versions User Agent

    Regular Expression ` ` i. Unit Tests. Safari 9 on iOS 9.3. Safari 9.1 on Mac OS X (El Capitan) Safari 11 on iOS 11.4. Safari 11.1 on Mac OS X (El Capitan) Safari 12.1 on iOS 12.2. Safari 12.1 on macOS (Mojave) Safari 13 on iOS 13.1. Safari 13 on macOS (Mojave) Safari 8 on Mac OS X (Yosemite)

  5. regex

    The regular expression represented by this component. To navigate the symbols, press Up Arrow, Down Arrow, Left Arrow or Right Arrow

  6. Use of regular expressions in macOS search fields

    Jan 17, 2017 at 22:24. Actually, your example "\s" AND "an" AND "\s" above is incorrect. At least in my version of Preview (macOS 10.15), "\s" AND "an" AND "\s" and simply searching "an" (with quotes) give the exact same result with respect to finding the word "an" (surrounded by spaces). What including "AND \s" does is to add the additional ...

  7. Does Safari support JavaScript RegExp?

    VikingOSX. 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: One then enables Allow JavaScript from Apple Events from the Safari Develop menu ...

  8. Workaround for Lookbehind Regex in Safari

    Lookbehind regex are very powerful but they are not supported in all browsers. Non V8 browsers such as Safari don't support them. Let's run the same example in Safari:

  9. Safari Support with XRegExp 0.2.2

    Posted on July 12, 2007 June 24, 2009 Author Steven Levithan Categories Cross-Browser Issues, JavaScript, Project Releases, Regular Expressions Tags xregexp 3 thoughts on "Safari Support with XRegExp 0.2.2"

  10. javascript

    2. Different regex engines have different tolerance to catastrophic backtracking prone patterns. Yours is a catastrophic backtracking prone pattern as you quantify (.+) with the {2,} quantifier that makes (.+) match two or more times (that is, match one or more times twice or more, which makes it fail very slowly with non-matching patterns.)

  11. "regular expression"

    Lookbehind in JS regular expressions. - OTHER. The positive lookbehind ( (?<= )) and negative lookbehind ( (?<! )) zero-width assertions in JavaScript regular expressions can be used to ensure a pattern is preceded by another pattern. Usage % of.

  12. Regex not compatible with safari, need help to convert

    regex101: build, test, and debug regex. Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java. Features a regex quiz & library. It would be very helpful if you showed what you were trying to match. You can't have lookbehind if you need to support Safari, but you can definitely ...

  13. 174931

    As somebody who uses lookbehind in regex for a lot of my code, I would like to show my strong support for the resolution of this issue. Considering that all modern browsers -- save for Safari/WebKit -- support regex lookbehind, as a web developer, I find it frustrating that WebKit is the only modern browser engine which does not support this.

  14. osx

    The only browser with native support for Regex searches I was able to find is Konqueror. It's available onley for Linux systems. ... found nothing for Safari; Regex Search add-on for Mozilla Firefox; You can use RegEx search in Google Chrome DevTools, typing Ctrl + Shift + F on Windows or Command + F on Mac, but it will search in the code and ...

  15. Lookbehind regexes don't work in Safari #10

    add a new method Interscript.transliterate_async which would call Interscript.transliterate or Interscript.transliterate_safari (the maps would need to be compiled twice, once for Safari, once for the rest) - this path is in my opinion the fastest and the most effortless

  16. JavaScript built-in: RegExp: test

    Browser support tables for modern web technologies. Created & maintained by @Fyrd, design by @Lensco. Support data contributions by the GitHub community. Usage share statistics by StatCounter GlobalStats for April, 2024 Location detection provided by ipinfo.io. Browser testing done via

  17. Regex is working on Chrome but not in Safari

    The following regex is working just fine on Chrome, but it breaks in Safari with the following error: SyntaxError: Invalid regular expression: invalid group specifier name. Regex: /^[a-zA-Z0-9.!#$%...

  18. safari test

    Regular Expression to test. Character classes. any character except newline \w \d \s: word, digit, whitespace

  19. ‎Regex for Safari on the App Store

    One click to copy all matched text on page. Keyboard shortcut support, "Command+Shift+F" to call the plugin, "Enter/Shift + Enter" to go to next/previous match. No need to type in regex every time. All your regular expressions are saved locally on your device. Customizable highlight color, among all the other options you can tweak to better ...

  20. Updating a Web Browser

    Follow these steps to enable automatic updates: Open System Preferences. Go to Software Update. Check the box that says Automatically keep my Mac up to date. iOS. Safari updates are included with iOS updates. To enable automatic updates: Go to Settings > General > Software Update. Enable Automatic Updates.

  21. Javascript RegEx safari issue

    This is a word boundary Regular Expression which support non latin letters , it works in Chrome but not in Safari. any alternative solution? new RegExp("(?<=[\\s ...

  22. Cisco Webex Meetings Meeting Information and Metadata Issue June 2024

    Cisco Webex Meetings customers should continue to monitor regular support channels for further communication and are encouraged to use those channels for further questions. As always, Cisco will communicate through established channels. Cisco welcomes the opportunity to engage with customers and the security community to enhance security across ...

  23. javascript

    The regex I used works in Chrome, but not in Safari and after doing google search I realized that Safari doesn't yet support lookbehinds. Is there another way to write the following regex so that it does the above, but works in Safari too?

  24. SpaceX Gets US License to Launch Massive Starship Rocket

    June 4, 2024 at 1:44 PM PDT. Listen. 1:30. SpaceX received the go-ahead from US air safety regulators to launch its massive Starship rocket on a fourth major test flight, as the Elon Musk -led ...