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

re = /^(?<pos>.{4})\s(?<naam>.{25})\s(?<plaats>.{25})\s(?<tijd>.{8})/m str = ' 25 Gerry Trimpe Middelburg 1:46:04 26 Sylvia Glerum-witkam Delta Sport 1:46:35 27 Annette de bot THOR 1:47:27 28 Ernesta Verburg Dreischor 1:47:40 29 Daniella Evers Middelburg 1:47:48 30 Corine Poot Arnhem 1:48:05 31 Lian Zorge Zierikzee 1:48:37 32 Miranda Kwakkelaar Middelburg 1:50:42 33 Lianne wijsman Delta Sport 1:51:17 34 Esther Oldenburger Brielle 1:51:40 35 Katinka Schotanus Kloetinge 1:51:47 36 Heleen van der Linden PAC 1:52:04 37 Cora Verheij Abbenbroek 1:54:22 38 Connie Huibregtse Delta Sport 1:54:55 39 Jacqueline Meijers AV \'56 1:55:07 40 Josien van Waarde Middelburg 1:55:52 41 Liesbet Peeters Kasterlee 1:56:02 42 Marianne zwart Helmond 1:56:41 43 MariƎlle Lauwers Helmond 1:56:43 44 Ieke de Jonge \'s-Gravenhage 1:57:48 45 Joke van Paassen Rockanje 1:58:00 46 Mireille van der Veer Brielle 1:58:02 47 Sylvia Verkaart Kapelle 1:58:33 48 Lenneke Ruijsink AV \'56 1:59:06 49 Nicole Ehbel Steenbergen Nb 1:59:16 50 Laila Heshof Steenbergen Nb 1:59:18 51 Marleen Verboom Delta Sport 1:59:20 52 Mandy Bootsma Strijen 2:00:16 53 Debora Hampel- van Kapel Oud-Vossemeer 2:01:24 54 Janneke van Westen Sint Philipsland 2:01:29 55 Petra van den Doel Zierikzee 2:02:41 56 Jolanda ter Steege Dinteloord 2:03:42 57 Marleen Hozee Vlissingen 2:03:52 58 Cynthia Janse Delta Sport 2:03:54 59 Esther Brouwer Vlissingen 2:04:46 60 Regine Boogert Middelburg 2:04:48 61 Miriam Bijl Zuid-Beijerland 2:04:51 62 Mariel Kers Dordrecht 2:18:43 63 Pippi Langkous Scharendijke 2:23:26 64 Monique Coppejans Nieuwdorp Zld 2:33:34' # Print the match result str.scan(re) do |match| puts match.to_s end

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