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

/
/
i

Test String

Substitution

Processing...

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"\s+TStatusBar" test_str = ("inherited FormPadrao: TFormPadrao\n" " Left = 354\n" " Top = 155\n" " Caption = 'FormPadrao'\n" " ClientHeight = 342\n" " ClientWidth = 655\n" " KeyPreview = True\n" " PopupMenu = MnPop_Principal\n" " OnCloseQuery = FormCloseQuery\n" " OnDeactivate = FormDeactivate\n" " ExplicitWidth = 671\n" " ExplicitHeight = 381\n" " DesignSize = (\n" " 655\n" " 342)\n" " PixelsPerInch = 96\n" " TextHeight = 15\n" " object Bv_Top: TBevel [0]\n" " Left = 0\n" " Top = 0\n" " Width = 655\n" " Height = 2\n" " Align = alTop\n" " end\n" " object Sb_FormPadrao: TStatusBar [1]\n" " Left = 0\n" " Top = 317\n" " Width = 655\n" " Height = 25\n" " Panels = <\n" " item\n" " Bevel = pbNone\n" " Text = 'Usu'#225'rio'\n" " Width = 100\n" " end\n" " item\n" " Bevel = pbNone\n" " Width = 50\n" " end>\n" " ParentColor = True\n" " ParentFont = True\n" " UseSystemFont = False\n" " ExplicitTop = 323\n" " end\n" " object Pn_BaseToolBar: TPanel [2]\n" " Left = 0\n" " Top = 2\n" " Width = 655\n" " Height = 73\n" " Align = alTop\n" " BevelOuter = bvNone\n" " ParentColor = True\n" " TabOrder = 2\n" " end\n" " object Pn_BaseGrid: TPanel [3]\n" " Left = 0\n" " Top = 75\n" " Width = 655\n" " Height = 242\n" " Align = alClient\n" " BevelOuter = bvNone\n" " BorderWidth = 3\n" " ParentColor = True\n" " TabOrder = 4\n" " ExplicitLeft = 32\n" " ExplicitTop = 95\n" " ExplicitHeight = 222\n" " end\n" " inherited MinMax: TmgMinMax\n" " Top = 7\n" " MinTrackSize.X = 450\n" " MinTrackSize.Y = 300\n" " ExplicitTop = 7\n" " end\n" " object Mn_Principal: TMainMenu [6]\n" " Left = 4\n" " Top = 36\n" " object miTabela: TMenuItem\n" " Caption = '&Tabela'\n" " object miInserir: TMenuItem\n" " Caption = '&Inserir'\n" " end\n" " object miApagar: TMenuItem\n" " Caption = '&Apagar'\n" " end\n" " object miPropriedades: TMenuItem\n" " Caption = '&Editar'\n" " end\n" " object N4: TMenuItem\n" " Caption = '-'\n" " end\n" " object miFechar: TMenuItem\n" " Caption = '&Fechar'\n" " OnClick = miFecharClick\n" " end\n" " end\n" " object miEditar1: TMenuItem\n" " Caption = '&Editar'\n" " object miRecortar1: TMenuItem\n" " Caption = '&Recortar'\n" " end\n" " object miCopiar1: TMenuItem\n" " Caption = '&Copiar'\n" " end\n" " object miColar1: TMenuItem\n" " Caption = '&Colar'\n" " end\n" " end\n" " object miExibir: TMenuItem\n" " Caption = '&Exibir'\n" " object miBarradeFerramentas: TMenuItem\n" " Caption = 'Barra de &Ferramentas'\n" " object miNaoExibir: TMenuItem\n" " Caption = '&N'#227'o Exibir'\n" " GroupIndex = 1\n" " RadioItem = True\n" " OnClick = mi_NaoExibirClick\n" " end\n" " object N5: TMenuItem\n" " Caption = '-'\n" " GroupIndex = 1\n" " RadioItem = True\n" " end\n" " object miAlto: TMenuItem\n" " Caption = '&Alto'\n" " GroupIndex = 1\n" " RadioItem = True\n" " OnClick = mi_AltoClick\n" " end\n" " object miBaixo: TMenuItem\n" " Caption = '&Baixo'\n" " GroupIndex = 1\n" " RadioItem = True\n" " OnClick = mi_BaixoClick\n" " end\n" " end\n" " object miBarradeStatus: TMenuItem\n" " Caption = 'Barra de &Status'\n" " OnClick = mi_BarradeStatusClick\n" " end\n" " object mi_SepN3: TMenuItem\n" " Caption = '-'\n" " end\n" " object mi_Informacoesdajanela1: TMenuItem\n" " Caption = 'Informa'#231#245'es desta Janela'\n" " OnClick = mi_Informacoesdajanela1Click\n" " end\n" " object mi_Sepm9: TMenuItem\n" " Caption = '-'\n" " Visible = False\n" " end\n" " object mi_OcorrenciaAuditoria: TMenuItem\n" " Caption = 'Logs de Auditoria'\n" " Visible = False\n" " OnClick = mi_OcorrenciaAuditoriaClick\n" " end\n" " end\n" " object Mi_Ajuda: TMenuItem\n" " Caption = '&Ajuda'\n" " object Mi_AjudaProcesso: TMenuItem\n" " Caption = 'Ajuda &Processo'\n" " ShortCut = 112\n" " OnClick = Mi_AjudaProcessoClick\n" " end\n" " object Mi_AjudaTela: TMenuItem\n" " Caption = 'Ajuda &Tela'\n" " ShortCut = 16496\n" " OnClick = Mi_AjudaTelaClick\n" " end\n" " object Mi_HistoricoAlteracoes: TMenuItem\n" " Caption = '&Hist'#243'rico de altera'#231#245'es'\n" " Visible = False\n" " OnClick = Mi_HistoricoAlteracoesClick\n" " end\n" " end\n" " end\n" " inherited mgPopupImpressao: TmgPopupMenu\n" " Left = 4\n" " end\n" " object MnPop_Principal: TPopupMenu\n" " Left = 34\n" " Top = 36\n" " object mi_Inserir: TMenuItem\n" " Caption = '&Inserir'\n" " end\n" " object mi_Apagar: TMenuItem\n" " Caption = '&Apagar'\n" " end\n" " object mi_Editar: TMenuItem\n" " Caption = '&Editar'\n" " end\n" " object N1: TMenuItem\n" " Caption = '-'\n" " end\n" " object mi_BarradeFerramentas: TMenuItem\n" " Caption = '&Barra de Ferramentas'\n" " object mi_NaoExibir: TMenuItem\n" " Caption = '&N'#227'o Exibir'\n" " GroupIndex = 1\n" " RadioItem = True\n" " OnClick = mi_NaoExibirClick\n" " end\n" " object N2: TMenuItem\n" " Caption = '-'\n" " GroupIndex = 1\n" " RadioItem = True\n" " end\n" " object mi_Alto: TMenuItem\n" " Caption = '&Alto'\n" " GroupIndex = 1\n" " RadioItem = True\n" " OnClick = mi_AltoClick\n" " end\n" " object mi_Baixo: TMenuItem\n" " Caption = '&Baixo'\n" " GroupIndex = 1\n" " RadioItem = True\n" " OnClick = mi_BaixoClick\n" " end\n" " end\n" " object mi_BarradeStatus: TMenuItem\n" " Caption = 'Ba&rra de Status'\n" " OnClick = mi_BarradeStatusClick\n" " end\n" " end\n" "end") subst = " TMgStatusBar" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 1, re.IGNORECASE) if result: print (result) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html