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

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