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

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