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"
"

Test String

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"Marca[s]{0,}[:]{0,}[.]{0,}[ ]{0,}[A-Z]{3,}[ ]{0,}[A-Z]{0,}[ ]{0,}[A-Z]{0,}" test_str = ("RESUMEN DE AUTOMÓVILES RESIDENTES Número de Póliza: 0003098447\n" "Vigencia Desde: 12:00 Hrs. 02/12/2020\n" "Hasta: 12:00 Hrs. 02/12/2021\n" "Fecha de Emisión: 12:00 Hrs. 02/12/2020\n" "DATOS DEL CONTRATANTE\n" "Nombre: AYALA MARTINEZ, JOSE RFC.: AAMJ4410183W0\n" " Domicilio: ANDADOR 17, DPTO. ENTRADA B. RESIDENCIAL ACUEDUCTO C.P.: 7270\n" "DE GUADA. GUSTAVO A. MADERO. CDMX\n" "DATOS DE LA PÓLIZA\n" "Línea: AUTOMÓVILES RESIDENTES Unidades A Riesgo: 1 Prima: $4,000.00\n" "Clave Agente: 95099 Prima Neta: $2,513.45\n" "Nombre: BAJA TU SEGURO AGENTE DE SEGUROS S.A. DE C.V. Financiamiento: $0.00\n" "Forma de pago: ANUAL Gastos de Expedición: $590.00\n" "Moneda: Pesos Gastos de expedición $ 400,00\n" "Exentos de IVA:\n" "I.V.A.: $496.55\n" "Prima Total: $4,000.00\n" "Monterrey (81) 8318 3874\n" "En caso de Siniestro, se puede\n" "reportar a través de nuestra App O llame Ciudad de México (55) 5140 3050\n" "Disponible para iOS y Android Cualquier Parte de la\n" "800 723 4763\n" "República Mexicana\n" "SEGUROS AFIRME S.A. DE C.V., AFIRME GRUPO FINANCIERO (en lo sucesivo la \"Institución\"), asegura a favor de la persona\n" "arriba citada (en lo sucesivo el \"Asegurado\") el vehículo descrito en la presente Carátula, contra los riesgos descritos más\n" "adelante y durante la vigencia establecida, sujeto a las condiciones generales y en su caso particulares entregadas junto con esta\n" "Carátula.\n" "En cumplimiento a lo dispuesto en el artículo 202 de la ley de instituciones de seguros y fianzas, la\n" "documentación contractual y la nota técnica que integran este producto, quedaron registradas ante\n" "la comisión nacional de seguros y fianzas, a partir del día 19 de diciembre de 2018, con el número:\n" "CNSF-S0094-0685-2018\n" "En testimonio de lo cual SEGUROS AFIRME, S.A. de C.V., AFIRME GRUPO FINANCIERO, Firma la presente forma en\n" "Monterrey Nuevo León, México\n" "Página: 1CARATULA DE AUTOMÓVILES RESIDENTES Número de Póliza: 0003098447Inciso: 000\n" "Vigencia desde: 12:00 HRS. 02/12/2020\n" "Hasta: 12:00 HRS. 02/12/2021\n" "Fecha de Emisión 12:00 HRS. 02/12/2020\n" "DATOS DEL ASEGURADO\n" " Nombre: AYALA MARTINEZ, JOSE\n" " Domicilio: ANDADOR 17, DPTO. ENTRADA B. RESIDENCIAL R.F.C.: AAMJ4410183W0\n" "ACUEDUCTO DE GUADA. GUSTAVO A. MADERO. CDMX\n" "Contratante: AYALA MARTINEZ, JOSE C.P.: 7270\n" " Conductor: AYALA MARTINEZ, JOSE\n" "DATOS DEL VEHÍCULO\n" "Marca: CHEVROLET Modelo: 2018 Tipo: AUTOMÓVILES\n" "Versión: CHEVROLET AVEO 1.5 LS PAQ A TM Número de Serie: LSGHD52HXJD152678\n" " 5\n" "Placas: W17AWP Pasajeros: Número de Motor: HECHO EN CHINA\n" "Uso: PARTICULAR Clave: 1006005601 Tipo de carga:\n" "COBERTURAS LÍMITE MÁXIMO DE DEDUCIBLE PRIMA\n" " RESPONSABILIDAD\n" "DAÑOS MATERIALES VALOR COMERCIAL +10 5 % $ 218,58\n" "ROBO TOTAL VALOR COMERCIAL +10 10 % $ 84,60\n" "RESPONSABILIDAD CIVIL LUC $ 2.500.000,00 $ 499,72\n" "GASTOS MÉDICOS OCUPANTES $ 500.000,00 $ 148,95\n" "ASISTENCIA JURÍDICA AMPARADA $ 200,00\n" "ASISTENCIA VIAL AMPARADA $ 250,00\n" "RESPONSABILIDAD CIVIL EN USA Y CANADÁ AMPARADA $ 0,00\n" "AUTO SIGUE AFIRME AMPARADA $ 550,00\n" "RESPONSABILIDAD CIVIL EN EXCESO POR MUERTE $ 3.000.000,00 $ 167,81\n" "EXENCIÓN DE DEDUCIBLES PERDIDA TOTAL DAÑOS MATERIALES AMPARADA $ 11,16\n" "EXENCIÓN DE DEDUCIBLES POR ROBO TOTAL AMPARADA $ 8,46\n" "EXTENSIÓN DE RESPONSABILIDAD CIVIL CONDUCTOR HABITUAL $ 2.500.000,00 $ 74,96\n" "ACCIDENTES AUTOMOVILÍSTICOS AL CONDUCTOR $ 100.000,00 $ 33,24\n" "AUTO AGENCIA AMPARADA $ 105,01\n" "ROBO PARCIAL AMPARADA $ 160,95\n" "Pagina: 1") matches = re.search(regex, test_str) if matches: print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group())) for groupNum in range(0, len(matches.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum))) # 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