Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

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"^.*?([\d.]+\s*(x|х)\s*[\d.]+\s*\/.*ET-?\d+).*$" test_str = ("1) София 5.5.x13/4x98 ET35\n" "2) Палладика 7x16/5x139.7 D98 ET5 Алмаз черный \n" "3) 35TH Anniversary 8x18/5x108 ET27 Black \n" "4)Уран 6x14/4x108 ET37\n" "1) NG277 5.5x13/4x100 D73.1 ET38 \n" "BKF = 5.5x13/4x100 D73.1 ET38\n" "2) MC7/B 7x17/5x114.3 D70.6 ET54 \n" "Silver = 7x17/5x114.3 D70.6 ET54\n" "3) S 7 Modify 7.5x18/5x112 D73 ET42 \n" "Silver = 7.5x18/5x112 D73 ET42\n" "4) MK-Course Mod.08 7.5x18/5x100 D56.1 ET55\n" "5) Fever-5R 8x18/5x120 D74.1 ET15 Black Mirror\n" "6) R6162 9x20/5x108 D67.1 ET40 S\n" "7) 35 Anniversary 8x18/5x120 ET34 Black\n" "8) Lounge 8 & 10 8x18/5x110 D75 ET38 Black\n" "9) RSL 5068TL 8.5x18/5x112 D71.6 ET40 MLB\n" "10 Килиманджаро-5-оригинал 6x15/5x114.3 D67.1 ET52.5\n" "11) RK L31F 6x15/4x100 D54.1 ET48 S\n" "12 X-113 7x17/5x115 D70.1 ET41 BK/FP\n" "H-323 8x15/6x139.7 H-323 8x15/6x139.7 D110.5 ET-28 HS \n" "D/P H-526 7x15/6x139.7 D110.5 ET-13 HS \n" "LS182 10x15/5x139.7 D108.5 ET-40 BKF \n" "Талисман-Мега 7х16/5x139.7 D95.3 ET35 \n" "блэк платинум P0457 8.5 x 20/5x100 D73.1 ET35 \n" "Chrome 7100 7x16/6x139.7 D112.2 ET-15 Silver") subst = "\\1" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 0, re.MULTILINE) 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