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

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)\b((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:(?<!\.)\b|\.)){4}" Local $sString = "#Ejemplos de codigo fuente del lenguaje de programacion Ruby" & @CRLF & _ "" & @CRLF & _ "#Aritmetica basica" & @CRLF & _ "resultado='5 * (12 - 8) + -15'" & @CRLF & _ "puts resultado" & @CRLF & _ "puts 98 + (59872 / (13 * 8)) * -52" & @CRLF & _ "" & @CRLF & _ "#Textos" & @CRLF & _ "puts "Hola, mundo!"" & @CRLF & _ "puts """ & @CRLF & _ "puts "Adiós."" & @CRLF & _ "puts "Me gusta" + "el pastel de manzana."" & @CRLF & _ "puts "Mi IP es: 192.168.9.10"" & @CRLF & _ "puts "ragustin726@gmail.com"" & @CRLF & _ "puts "https://www.facebook.com"" & @CRLF & _ "puts "31/01/2021/"" & @CRLF & _ "" & @CRLF & _ "277.893.21.2" & @CRLF & _ "" & @CRLF & _ "#Variables" & @CRLF & _ "myString = '...puedes decir eso de nuevo...'" & @CRLF & _ "puts myString" & @CRLF & _ "name = 'Patricia Rosanna Jessica Mildred Oppenheimer'" & @CRLF & _ "ip= 10.0.0.1" & @CRLF & _ "correo='roberto_840@hotmail.com'" & @CRLF & _ "direccion='https://www.google.com'" & @CRLF & _ "fecha = '19/07/2001'" & @CRLF & _ "" & @CRLF & _ "#Concatenaciones" & @CRLF & _ "puts 'Me llamo ' + name + '.'" & @CRLF & _ "puts 'Wow! "' + name + '" es un nombre realmente largo!'" & @CRLF & _ "composer1 = 'Mozart'" & @CRLF & _ "puts composer1 + ' fue "el amo", en su día.'" & @CRLF & _ "composer = 'Beethoven'" & @CRLF & _ "puts 'Pero yo prefiero a ' + composer1 + ', personalmente.'" & @CRLF & _ "" & @CRLF & _ "#Conversiones" & @CRLF & _ "var1 = 2" & @CRLF & _ "var2 = '5'" & @CRLF & _ "puts var1.to_s + var2" & @CRLF & _ "var1 = 2" & @CRLF & _ "var2 = '5'" & @CRLF & _ "puts var1.to_s + var2" & @CRLF & _ "puts var1 + var2.to_i" & @CRLF & _ "" & @CRLF & _ "#Condicionales " & @CRLF & _ "puts 1 > 2" & @CRLF & _ "puts 1 < 2" & @CRLF & _ "puts 5 >= 5" & @CRLF & _ "puts 5 <= 4" & @CRLF & _ "puts 1 == 1" & @CRLF & _ "puts 2 != 1" & @CRLF & _ "puts 'gato' < 'perro'" & @CRLF & _ "" & @CRLF & _ "#Ramificaciones" & @CRLF & _ "puts 'Hola, y bienvenido a la clase de 7mo año.'" & @CRLF & _ "puts 'Me llamo Mrs. Gabbard. ¿Tú nombre es...?'" & @CRLF & _ "nombre = gets.chomp" & @CRLF & _ "" & @CRLF & _ "if nombre == nombre.capitalize" & @CRLF & _ " puts 'Por favor, toma asiento ' + nombre + '.'" & @CRLF & _ "else" & @CRLF & _ " puts '¿' + nombre + '? Quieres decir ' + nombre.capitalize + ', ¿cierto?'" & @CRLF & _ " puts '¿No sabes escribir tu propio nombre?'" & @CRLF & _ " respuesta = gets.chomp" & @CRLF & _ "" & @CRLF & _ " if respuesta.downcase == 'si'" & @CRLF & _ " puts '¡Hum! Bueno, ¡siéntese!'" & @CRLF & _ " else" & @CRLF & _ " puts '¡SALGA DEL SALON!'" & @CRLF & _ " end" & @CRLF & _ "end" & @CRLF & _ "" & @CRLF & _ "#Bucles" & @CRLF & _ "comando = ''" & @CRLF & _ "while comando != 'adios'" & @CRLF & _ " puts comando" & @CRLF & _ " comando = gets.chomp" & @CRLF & _ "end" & @CRLF & _ "puts '¡Vuelve pronto!'" & @CRLF & _ "" & @CRLF & _ "#Operadores logicos" & @CRLF & _ "edad=18" & @CRLF & _ "sexo="Mujer"" & @CRLF & _ "ocupacion="Estudiante"" & @CRLF & _ "if edad>=18 and sexo=="Mujer" and ocupacion="Estudiante"" & @CRLF & _ " puts "Mujer mayor de edad estudiante"" & @CRLF & _ "end" & @CRLF & _ "" & @CRLF & _ "edad=18" & @CRLF & _ "if edad>=18 or edad<=25" & @CRLF & _ " puts "Tu edad esta entre los 18 y 25 años"" & @CRLF & _ "end" & @CRLF & _ "" & @CRLF & _ "#Modulos y potencias" & @CRLF & _ "puts 5**2" & @CRLF & _ "puts 5**0.5" & @CRLF & _ "puts 7/3" & @CRLF & _ "puts 7%3" & @CRLF & _ "puts 365%7" & @CRLF & _ "" & @CRLF & _ "#Lectura de archivos" & @CRLF & _ "content1 = File.read("imagen.jpg") # lee el archivo" & @CRLF & _ "content2 = File.read("contenido.png")" & @CRLF & _ "lines = content.split("\n") # divide el contenido en líneas" & @CRLF & _ "" & @CRLF & _ "# recorre las líneas y las imprime" & @CRLF & _ "lines.each do |line|" & @CRLF & _ " puts line" & @CRLF & _ "end" 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