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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)(^\w.*\n\n)+(^(##.*\n)+)" Local $sString = "tab_bar_edge top" & @CRLF & _ "" & @CRLF & _ "## Which edge to show the tab bar on, top or bottom" & @CRLF & _ "" & @CRLF & _ "tab_bar_margin_width 0.0" & @CRLF & _ "" & @CRLF & _ "## The margin to the left and right of the tab bar (in pts)" & @CRLF & _ "" & @CRLF & _ "tab_bar_margin_height 0.0 0.0" & @CRLF & _ "" & @CRLF & _ "## The margin above and below the tab bar (in pts). The first number" & @CRLF & _ "## is the margin between the edge of the OS Window and the tab bar and" & @CRLF & _ "## the second number is the margin between the tab bar and the" & @CRLF & _ "## contents of the current tab." & @CRLF & _ "" & @CRLF & _ "tab_bar_style fade" & @CRLF & _ "" & @CRLF & _ "## The tab bar style, can be one of:" & @CRLF & _ "## " & @CRLF & _ "## fade" & @CRLF & _ "## Each tab's edges fade into the background color (see tab_fade)" & @CRLF & _ "## slant" & @CRLF & _ "## Tabs look like the tabs in a physical file" & @CRLF & _ "## separator" & @CRLF & _ "## Tabs are separated by a configurable separator (see tab_separator)" & @CRLF & _ "## powerline" & @CRLF & _ "## Tabs are shown as a continuous line with "fancy" separators" & @CRLF & _ "## (see tab_powerline_style)" & @CRLF & _ "## custom" & @CRLF & _ "## A user-supplied Python function called draw_tab is loaded from the file" & @CRLF & _ "## tab_bar.py in the kitty config directory. For examples of how to" & @CRLF & _ "## write such a function, see the functions named draw_tab_with_* in" & @CRLF & _ "## kitty's source code: kitty/tab_bar.py. See also" & @CRLF & _ "## this discussion https://github.com/kovidgoyal/kitty/discussions/4447" & @CRLF & _ "## for examples from kitty users." & @CRLF & _ "## hidden" & @CRLF & _ "## The tab bar is hidden. If you use this, you might want to create a" & @CRLF & _ "## mapping for the https://sw.kovidgoyal.net/kitty/actions/#select-tab" & @CRLF & _ "## action which presents you with a list of tabs and allows for easy" & @CRLF & _ "## switching to a tab." & @CRLF & _ "" & @CRLF & _ "tab_bar_align left" & @CRLF & _ "" & @CRLF & _ "## The horizontal alignment of the tab bar, can be one of: left," & @CRLF & _ "## center, or right." & @CRLF & _ "" & @CRLF & _ "tab_bar_min_tabs 2" & @CRLF & _ "" & @CRLF & _ "## The minimum number of tabs that must exist before the tab bar is" & @CRLF & _ "## shown" & @CRLF & _ "" & @CRLF & _ "tab_switch_strategy previous" & @CRLF & _ "" & @CRLF & _ "## The algorithm to use when switching to a tab when the current tab" & @CRLF & _ "## is closed. The default of previous will switch to the last used" & @CRLF & _ "## tab. A value of left will switch to the tab to the left of the" & @CRLF & _ "## closed tab. A value of right will switch to the tab to the right of" & @CRLF & _ "## the closed tab. A value of last will switch to the right-most tab." & @CRLF & _ "" & @CRLF & _ "tab_fade 0.25 0.5 0.75 1" & @CRLF & _ "" & @CRLF & _ "## Control how each tab fades into the background when using fade for" & @CRLF & _ "## the tab_bar_style. Each number is an alpha (between zero and one)" & @CRLF & _ "## that controls how much the corresponding cell fades into the" & @CRLF & _ "## background, with zero being no fade and one being full fade. You" & @CRLF & _ "## can change the number of cells used by adding/removing entries to" & @CRLF & _ "## this list." & @CRLF & _ "" & @CRLF & _ "tab_separator " ┇"" & @CRLF & _ "" & @CRLF & _ "## The separator between tabs in the tab bar when using separator as" & @CRLF & _ "## the tab_bar_style." & @CRLF & _ "" & @CRLF & _ "tab_powerline_style angled" & @CRLF & _ "" & @CRLF & _ "## The powerline separator style between tabs in the tab bar when" & @CRLF & _ "## using powerline as the tab_bar_style, can be one of: angled," & @CRLF & _ "## slanted, or round." & @CRLF & _ "" & @CRLF & _ "tab_activity_symbol none" & @CRLF & _ "" & @CRLF & _ "## Some text or a unicode symbol to show on the tab if a window in the" & @CRLF & _ "## tab that does not have focus has some activity. If you want to use" & @CRLF & _ "## leading or trailing spaces surround the text with quotes. See" & @CRLF & _ "## tab_title_template for how this is rendered." & @CRLF & _ "" & @CRLF & _ "tab_title_template "{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{title}"" & @CRLF & _ "" & @CRLF & _ "## A template to render the tab title. The default just renders the" & @CRLF & _ "## title with optional symbols for bell and activity. If you wish to" & @CRLF & _ "## include the tab-index as well, use something like: {index}:" & @CRLF & _ "## {title}. Useful if you have shortcuts mapped for goto_tab N. If you" & @CRLF & _ "## prefer to see the index as a superscript, use {sup.index}. In" & @CRLF & _ "## addition you can use {layout_name} for the current layout name," & @CRLF & _ "## {num_windows} for the number of windows in the tab and" & @CRLF & _ "## {num_window_groups} for the number of window groups (not counting" & @CRLF & _ "## overlay windows) in the tab. Note that formatting is done by" & @CRLF & _ "## Python's string formatting machinery, so you can use, for instance," & @CRLF & _ "## {layout_name[:2].upper()} to show only the first two letters of the" & @CRLF & _ "## layout name, upper-cased. If you want to style the text, you can" & @CRLF & _ "## use styling directives, for example:" & @CRLF & _ "## {fmt.fg.red}red{fmt.fg.tab}normal{fmt.bg._00FF00}green" & @CRLF & _ "## bg{fmt.bg.tab}. Similarly, for bold and italic:" & @CRLF & _ "## {fmt.bold}bold{fmt.nobold}normal{fmt.italic}italic{fmt.noitalic}." & @CRLF & _ "## Note that for backward compatibility, if {bell_symbol} or" & @CRLF & _ "## {activity_symbol} are not present in the template, they are" & @CRLF & _ "## prepended to it." & @CRLF & _ "" & @CRLF & _ "active_tab_title_template none" & @CRLF & _ "" & @CRLF & _ "## Template to use for active tabs, if not specified falls back to" & @CRLF & _ "## tab_title_template." & @CRLF & _ "" & @CRLF & _ "xxxxxactive_tab_foreground #000" & @CRLF & _ "active_tab_background #eee" & @CRLF & _ "active_tab_font_style bold-italic" & @CRLF & _ "inactive_tab_foreground #444" & @CRLF & _ "yyyyinactive_tab_background #999" & @CRLF & _ "zzzzzinactive_tab_font_style normal" & @CRLF & _ "" & @CRLF & _ "## Tab bar colors and styles" & @CRLF & _ "" & @CRLF & _ "tab_bar_background none" & @CRLF & _ "" & @CRLF & _ "## Background color for the tab bar. Defaults to using the terminal" & @CRLF & _ "## background color." & @CRLF & _ "" & @CRLF & _ "tab_bar_margin_color none" & @CRLF & _ "" & @CRLF & _ "## Color for the tab bar margin area. Defaults to using the terminal" & @CRLF & _ "## background color." & @CRLF & _ "" & @CRLF & _ "" Local $sSubst = "$2\n$1" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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