Regular Expressions 101

Save & Share

  • Regex Version: ver. 5
  • 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

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"^(К?[0-9, ()м]+) (?:Ламінат|Акція Ламінат) ([A-Za-z0-9\/( .]*[\d)]) (.+?)(?: \(\d|\s*$)" test_str = ("3924 Ламінат Parfe Floor 7/32 Дуб Мірандо (2,663)/10шт\n" "8199 Ламінат 8 Variostep Classic Дуб Альпійський (2,22м2)/9 шт.\n" "8766 Акція Ламінат 8 Венге Кіото (2,22м2)/9 шт.\n" "К395 Акція Ламінат 8 Дуб Торнадо (2,22 м2)/9 шт.\n" "34 818 Ламінат The BRUSH 8 Дуб Бежевий (1,996 м2)/8шт\n" "31 506 (32 065) Ламінат Neutral 4V (Trend world) Дуб Монумент (Дуб Дерби) (1,996 м2)/8шт\n" "27 610 (41404 (8мм) Ламінат Discovery 4V 10/32 Дуб Верден сніжний (1,646 м2)/8 шт\n" "145 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Модерн Білий\n" "33 680 Ламінат Extr. dynamic 8 Старий дуб Полліно фас. (1,996 м2)/8шт\n" "53 687 Ламінат Ambience 4V WR 10/33 Wolta Oak (1,624 м2)/8шт.\n\n" "60 040 Ламінат Vitality Deluxe 4V 8/32 Дуб Берлі (2.162 м2)/9шт.\n" "60 328 Ламінат Vitality Deluxe 4V 8/32 Дуб Амбарний (2.162 м2)/9шт.\n" "60 491 Ламінат Vitality Deluxe 4V 8/32 Дуб Вибілений (2.162 м2)/9шт.\n" "60 542 Ламінат Vitality Deluxe 4V 8/32 Дуб Елегантний (2.162 м2)/9шт.\n" "60 544 Ламінат Vitality Deluxe 4V 8/32 Горіх Селект (2.162 м2)/9шт.\n" "60 581 Ламінат Vitality Deluxe 4V 8/32 Дуб Суперіор (2.162 м2)/9шт.\n" "60 583 Ламінат Vitality Deluxe 4V 8/32 Дуб лакований натур. (2.162 м2)/9шт.\n" "60 584 Ламінат Vitality Deluxe 4V 8/32 Дуб Авеню (2.162 м2)/9шт.\n" "60 619 Ламінат Vitality Deluxe 4V 8/32 Дуб Білий промаслений (2.162 м2)/9шт.\n" "60 624 Ламінат Vitality Deluxe 4V 8/32 Ясень садовий (2.162 м2)/9шт.\n" "60 796 Ламінат Vitality Deluxe 4V 8/32 Дуб пісочний (2.162 м2)/9шт.\n" "60 900 Ламінат Vitality Deluxe 4V 8/32 Дуб сірувато-димчастий (2.162 м2)/9шт.\n" "60 902 Ламінат Vitality Deluxe 4V 8/32 Дуб Iпанема (2.162 м2)/9шт.\n" "60 903 Ламінат Vitality Deluxe 4V 8/32 Дуб Замшевий (2.162 м2)/9шт.\n" "60 904 Ламінат Vitality Deluxe 4V 8/32 Дуб Сумі (2.162 м2)/9шт.\n" "60 909 Ламінат Vitality Deluxe 4V 8/32 Дуб ретушований (2.162 м2)/9шт.\n" "Vitality Style 4V\n" "135 Ламінат Vitality Style 4V 8/32 Дуб Дуб Вибілений Сонячний (2.179 м2)/9шт\n" "137 Ламінат Vitality Style 4V 8/32 Дуб Вікторіанський Коричневий (2.179 м2)/9шт\n" "138 Ламінат Vitality Style 4V 8/32 Дуб Натуральний Бежевий (2.179 м2)/9шт\n" "145 Ламінат Vitality Style 4V 8/32 Дуб Модерн Білий (2.179 м2)/9шт\n" "148 Ламінат Vitality Style 4V 8/32 Дуб Чорний (2.179 м2)/9шт\n" "174 Ламінат Vitality Style 4V 8/32 Дуб Медовий (2.179 м2)/9шт\n" "177 Ламінат Vitality Style 4V 8/32 Дуб Морозний (2.179 м2)/9шт\n" "178 Ламінат Vitality Style 4V 8/32 Дуб Модерн Вишуканий (2.179 м2)/9шт\n" "179 Ламінат Vitality Style 4V 8/32 Дуб Гірський Сірий (2.179 м2)/9шт\n\n" "135 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Дуб Вибілений Сонячний\n" "137 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Вікторіанський Коричневий \n" "138 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Натуральний Бежевий\n" "145 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Модерн Білий\n" "148 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Чорний\n" "149 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Сірий океан\n" "174 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Медовий\n" "175 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Брендон\n" "177 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Морозний\n" "178 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Модерн Вишуканий\n" "179 Ламінат Vitality Style Aqua Protect 4V 8/32 Дуб Гірський Сірий\n") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.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