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
No Match

r"
"
g

Test String

Code Generator

Generated Code

$re = '//\*/?(\n|[^/]|[^*]/)*\*//'; $str = '/********************* * test * multiline */ /* next表示を半透明でなくする (カクつき防止のテスト) */ #content-tips-wrap { opacity: 1!important; } /* path /_ct/* */ /* なるほどねー */ /***** compact footer ****/ @import url(\'/static/dinoportal/custom/content-compactfooter.css\'); /***** Read All *****/ @import url(\'/static/dinoportal/custom/content-addmore.css\'); @requirejs: url(\'/static/dinoportal/custom/content-addmore.js\'); /* endpath */ /* ヘッダメニューを常にモバイルと同じにする */ @import url(\'/static/dinoportal/custom/header-menu-always-mobile.css\'); /* メニューフィードの写真・カードの先頭を大きく */ @import url(\'/static/dinoportal/custom/menufeed-big-leading.css\'); /* 写真・カードのフィードをモバイルで2列表示 */ @import url(\'/static/dinoportal/custom/feed-card-mobile-2cols.css\'); /* サイドバーを左に */ @import url(\'/static/dinoportal/custom/sidebar-left.css\'); /* サイドバーの要素をブロック分け */ @import url(\'/static/dinoportal/custom/sidebar-separate.css\'); /* コンテンツカバー画像をぼかす */ /* @import url(\'/static/dinoportal/custom/content-cover-blur.css\'); */ /* 各種色設定 (LESS記法) */ @import url(\'/static/dinoportal/custom/colors.less\'); /* ベース */ @colors-base: hsl(207, 40%, 15%); /* 文字 */ @colors-base-bg: white; /* 背景 */ /* 箱囲み要素 */ @colors-base-box: @colors-base; /* 文字 */ @colors-base-box-bg: fade(@colors-base, 12%); /* 背景 */ /* ヘッダ */ @colors-header: #eee; /* 文字 */ @colors-header-bg: black; /* 背景 */ @colors-header-shadow: black; /* ヘッダ下線 */ /* ヘッダメニュー */ @colors-header-menu: @colors-header; /* 文字 */ @colors-header-menu-bg: @colors-header-bg; /* 背景 */ /* ヘッダメニュー(選択中メニュー) */ @colors-header-menu-active: white; /* 文字 */ @colors-header-menu-active-bg: transparent; /* 背景 */ @colors-header-menu-active-mark: hsl(0,100%,35%); /* 下線 */ /* ウィジェット */ @colors-widget: @colors-base-box; /* 文字 */ @colors-widget-bg: @colors-base-box-bg; /* 背景 */ /* タイトル系 */ @colors-menufeed-title: black; /* メニューフィードのブロックタイトル */ @colors-contents-title: @colors-base; /* フィードのコンテンツタイトル */ /* 写真・カード型フィード */ @colors-cards-bg: #eee; /* 写真・カード型フィードの背景 */ /* コンテンツ */ @colors-content-heading: @colors-base; /* 見出し */ @colors-content-heading-decoration: @colors-base; /* 見出し装飾色 */ @colors-content-subheading: @colors-base; /* 小見出し */ @colors-content-subheading-decoration: @colors-base; /* 小見出し装飾色 */ @colors-content-body-link: @colors-base; /* コンテンツ内リンク */ @colors-content-body-link-active: @colors-base; /* コンテンツ内リンク(アクティブ/ホバー) */ @colors-content-quote: @colors-base-box; /* 引用ボックス(文字) */ @colors-content-quote-bg: @colors-base-box-bg; /* 引用ボックス(背景) */ @colors-content-box: @colors-base-box; /* 箱囲み段落(文字) */ @colors-content-box-bg: @colors-base-box-bg; /* 箱囲み段落(背景) */ /* モバイルでメニューフィードサイドバーの.widget要素を最下部にまとめる */ /* @adjustwidgets: ~`window._adjustwidgets = {start:10000, step:0}`; */ /* モバイル、メニューフィード、通常リスト型表示の後続要素のタイトルをボールドに */ @media (max-width:767px) { #newsfeed .newsfeed-block.newsfeed-all-display-type-list .wfcontent.not-has-display-type .content-title { font-weight:bold; font-size:110%; } } /* 記事小見出し */ .article > h3 { border:1px solid hsl(171, 80%, 45%); padding:.4em .5em .3em 1.5em; position:relative; } .article > h3:before { content:\'\'; position:absolute; top:.4em; left:.4em; bottom:.4em; width:.75em; background:hsl(171, 80%, 45%); } .article > h4 { font-size:100%; border-left:.2em solid hsl(171, 80%, 45%); padding-left:.4em; } /****** banners-2col debug *******/ .banners-2col { position:relative; } .banners-2col > a > img { display:block; width:100%; margin:0; padding:0; } .banners-2col > a { margin:0; padding:0; display:inline-block; position:relative; width:49%; width:-webkit-calc( 50% - 2px ); width:calc( 50% - 2px ); width:~"calc( 50% - 2px )"; /* for LESS */ display:inline-block; vertical-align:top; } .banners-2col > a:hover { text-decoration:none; } .banners-2col > a:nth-child(2n+1) { margin-right:2%; margin-right:4px; } .banners-2col > a:nth-child(n+3) { margin-top:4px; }'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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