Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • 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
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • 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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/https?\:\/\/(www.)?([a-z\.A-Z\-]+)\/.*/'; $str = 'https://thenextweb.com/dd/2014/04/08/ux-designers-side-drawer-navigation-costing-half-user-engagement/ https://developer.android.com/training/implementing-navigation/nav-drawer.html http://www.viralandroid.com/2015/09/android-sliding-menu-with-webview.html https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uac…Android&usg=AFQjCNFRk6d5AhBfonGM106Sad2tjoBT7g&sig2=kiMOjbXGWDcWRLpLOvyYQQ https://github.com/twbs/bootstrap/issues/4550 https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&cad=rja&uac…ypes%2F&usg=AFQjCNHRDjZYkePYfSuVIkV9e4XLWM0V_g&sig2=_jN849JNw4Zbp2s3Anlzgw http://stackoverflow.com/questions/24463890/open-webview-when-item-in-the-side-slide-menu-is-clicked https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=8&cad=rja&uac…s-popup&usg=AFQjCNFtDDELoRlF3_9SuoyJJ2kzZsDrDw&sig2=54H1u1WQd2NG0aywd6G4SQ https://support.proto.io/hc/en-us/community/posts/207856878-Sliding-sidebar-menu-s-links-do-not-work-on-Android-app https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&cad=rja&ua…b265b49&usg=AFQjCNEgo2JyzndfiLfH9duieqVd71CsVA&sig2=txF-3ZgdzHydpJJJ2BwT5Q https://developer.chrome.com/multidevice/android/customtabs http://www.howtogeek.com/237951/how-to-add-website-links-to-the-windows-10-start-menu/ https://paul.kinlan.me/deep-app-linking-on-android-and-chrome/ https://developers.google.com/apps-script/guides/dialogs https://material.io/guidelines/patterns/navigation-drawer.html https://help.shopify.com/manual/sell-online/online-store/menus-and-links https://books.google.com/books?id=IAVnDQAAQBAJ&pg=PT129&lpg=PT129&dq=androi…PsnBph0QJXDzjUY&hl=en&sa=X&ved=0ahUKEwi5_6G-9pXSAhXHurwKHc6RCQEQ6AEIgwEwEA https://lmjabreu.com/post/why-and-how-to-avoid-hamburger-menus http://stacktips.com/tutorials/android/navigation-drawer-android-example https://www.npmjs.com/package/cordova-universal-links-plugin https://support.wunderlist.com/customer/portal/articles/1767713 https://www.thepolyglotdeveloper.com/2014/12/open-dynamic-links-using-cordova-inappbrowser/ http://www.infoworld.com/article/2610416/web-browsers/web-browsers-50-tips-and-tricks-for-chrome-power-users.html https://vivaldi.com/?lang=en_US http://www.androidpolice.com/2016/01/20/google-android-app-can-now-open-links-in-chrome-custom-tabs-after-latest-update/ https://forum.ionicframework.com/t/external-links-in-side-menu-not-working/58384 http://dolphin.com/dolphin-for-android-phone-faqs/ https://www.facebook.com/business/help/312169205649942 http://blog.teamtreehouse.com/add-navigation-drawer-android http://forums.androidcentral.com/android-apps/593611-how-force-android-open-facebook-links-facebook-app.html https://plaid.com/docs/quickstart/ https://motorola-global-portal.custhelp.com/app/answers/prod_answer_detail/a_id/109551/p/30,6720,9583 http://blog.ionic.io/deeplinking-in-ionic-apps/ https://help.evernote.com/hc/en-us/articles/209004637-How-to-create-shortcuts-for-frequently-accessed-notes-notebooks-and-searches http://www.jqueryscript.net/tags.php?/side%20menu/ https://community.box.com/t5/Account-Information/How-To-Disable-Plugins-Add-Ons-Extensions-In-Multiple-Browsers/ta-p/19 https://support.mozilla.org/en-US/kb/using-tabs-firefox-android http://semantic-ui.com/modules/sidebar.html https://docs.citrix.com/en-us/xenmobile-apps/10/secure-web.html https://www.cnet.com/how-to/how-to-request-desktop-version-of-a-web-site-in-chrome-for-android/ http://mmenu.frebsite.nl/ http://tiddlywiki.com/ http://callmenick.com/post/slide-and-push-menus-with-css3-transitions https://www.lullabot.com/articles/navigation-and-deep-linking-with-react-native http://www.computerworld.com/article/2474114/android/4-hidden-settings-to-make-chrome-for-android-even-better.html http://help.tune.com/marketing-console/creating-and-using-deeplink-urls/ https://codepen.io/zavoloklom/pen/dIgco https://www.smashingmagazine.com/2012/06/responsive-menus-enhancing-navigation-on-mobile-websites/ https://get.slack.help/hc/en-us/articles/205166337-Customize-your-Slack-theme https://code.tutsplus.com/tutorials/mobile-web-quick-tip-phone-number-links--mobile-7667'; $subst = "$2"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php