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

import Foundation let pattern = #"\([^)]+,\s\d{4}(;\s[^)]+,\s\d{4})*\)"# let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines) let testString = #""" (Palacios et al., 2014) (Palacios et al., 2014) (a nivel fisiológico/hormonal) en chicos y chicas y se dan en ritmos de desarrollo desigual (Pérez-Pérez y Navarro-Soria, 2012) (Papalia et al., 2009) (Martín et al., 2011) (ciertas operaciones sobre las proposiciones: conjunción, disyunción…) y poner esta al servicio del recién adquirido pensamiento formal, pueden operar sobre las operaciones concretas, realizando así operaciones formales o de segundo orden (García-Madruga y Delval, 2010) (García-Madruga y Delval, 2010) (Pérez-Pérez y Navarro-Soria, 2012) (Palacios et al., 2014) (Martín et al., 2011) (es la parte que tienen afectada las personas con trastorno de déficit de atención, TDA). También se encarga de la toma de decisiones, la planificación y la regulación de la propia conducta y por esto termina de desarrollarse en la adolescencia, cuando los sujetos adquieren la capacidad de pensar sobre el pensamiento y la conducta (Goldberg, 2004) (Damasio, 2010) (Toro, 2010) (metaoperaciones). Podrán reflexionar sobre sí mismos y sobre diferentes realidades entre las posibles (García-Madruga y Delval, 2010) (Elkind, 1978) (ciberacoso, divulgación de información confidencial, acoso escolar…) y poco responsables (Mariscal et al., 2009) (Mariscal et al., 2009) (positiva o negativa) de su desarrollo y el bienestar con su nueva realidad (Palacios et al., 2014; Pérez-Pérez y Navarro-Soria, 2012) (Duke et al., 1982) (Palacios et al., 2014; Pérez y Navarro, 2012) (Pérez-Pérez y Navarro-Soria, 2012) (Martínez, 2010) (Palacios et al., 2014; Pérez-Pérez y Navarro-Soria, 2012) (Palacios et al., 2014; Pérez-Pérez y Navarro-Soria, 2012) (Martín et al., 2011) (Palacios et al., 2014) (Palacios et al., 2014; Pérez-Pérez y Navarro-Soria, 2012) (Martín et al., 2011) (la adolescencia) (Instagram, WhatsApp…) puede producir un sentimiento de aislamiento social (Martín et al., 2011) (Oliva et al., 2002) (Martín et al., 2011) (ser compañeros), se hace necesaria la afinidad (Fuertes et al., 2001) (afecto, apoyo…) que los chicos, tendrán redes sociales menos extensas que estos, cuyas necesidades suelen ser de logro o admiración (Martín et al., 2011) (Palacios et al., 2014) (Furman y Wehner, 1994) (Palacios et al., 2014) (figura 8), ya que el estilo de crianza que el adolescente ha experimentado configurará de manera decisiva la personalidad que se está formando (Palacios et al., 2014) (Palacios et al., 2014) (Palacios et al., 2014) (Palacios et al., 2014) (1936-…) propuso un modelo alternativo que diese cuenta de las diferencias de género y, tras su investigación con mujeres y niñas, encontró que, mientras que los varones estaban más interesados por el concepto abstracto de justicia, las mujeres se preocupaban más por las relaciones interpersonales y la responsabilidad a la hora de satisfacer las necesidades de los demás (Palacios et al., 2014) """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let matches = regex.matches(in: testString, range: stringRange) var result: [[String]] = [] for match in matches { var groups: [String] = [] for rangeIndex in 1 ..< match.numberOfRanges { let nsRange = match.range(at: rangeIndex) guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue } let string = (testString as NSString).substring(with: nsRange) groups.append(string) } if !groups.isEmpty { result.append(groups) } } print(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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression