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
No Match

r"
"
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"^(?P<num>\d{3}) (?P<nom>\w{1,3})\. \[(?P<start>.+?)\] (?P<name>.*) №(?P<_req_id>\d{0,3})$" test_str = ("100 I. [С начала] Открытие №\n" "101 I. [После жюри] Спонсоры №\n" "102 S. [С точки] Стихия №\n" "104 K. [С точки] Kim - Mayumi Suzuki-Part of Your World (OST Русалочка) №97\n" "106 DGJ. [Сразу] Molli, Itami Liska - Code Geass №160\n" "108 DGJ. [Сразу] Tenletters, Гарка - No Game No Life №107\n" "110 V. [Сразу~] Sirin, Sandr - Что значит быть человеком (Death Parade, Death Billiards) №137\n" "112 DSJ. [Сразу] Kaoru - Trinity Blood №34\n" "114 DSJ. [Сразу] Kanda - D.Gray-man - Hallow №179\n" "116 DSJ. [Сразу] GEKATA - Brave 10 (10 Храбрецов) №3\n" "118 DSJ. [Сразу] Nick Satomi - Naruto №143\n" "120 DSJ. [Сразу] Neko_48 - Touken Ranbu №1\n" "122 DSJ. [Сразу] Besenok - Little witch academia №130\n" "124 DSJ. [Сразу] Верука Соль - One Piece №118\n" "126 DSJ. [Сразу] Fler - Quan Zhi Gao Shou (Аватар короля) №4\n" "128 T. [С точки] B00-M - BTS-Go-Go №176\n" "130 DA. [Сразу] Ranmaru - Maiden Rose №123\n" "132 V. [Сразу~] Rat - Samurai Champloo №149\n" "132 V. [Сразу~] Rat - Samurai Champloo №149\n" "134 INK. [Неизвестно] U - Akira Yamaoka-The Promise (OST Silent Hill 2) №11\n" "136 DSE. [Сразу] Чиби-сан - Harry Potter (Minerva McGonagall) №120\n" "138 DSE. [Сразу] Toshi-tyan - Game of Thrones №200\n" "140 DSG. [Сразу] Алекс Крамер - The Witcher 3 - Wild Hunt №175\n" "142 DSG. [Сразу] РозЭль - Monster Super League №182\n" "143 DSG. [Сразу] Ihre_Schwermut - Nekopara (Neko Paradise) №117\n" "144 DSG. [Сразу] Skiv - PokemonGo №69\n" "148 VC. [Сразу~] Wendy - Vocaloid - Clip Rolling girl №13\n" "150 DGO. [Сразу] BonSu - Misha Aro, Polina_Chan - Krainar & wild №42\n" "152 DSO. [С точки] Трюмст - Боевой Шаман №41\n" "154 DSO. [Сразу] PAIN - Сильмариллион-Саурон №84\n" "156 DSO. [Сразу] Itami Liska - Pixiv Fantasia - Fallen Kings-Ruri Unsou №52\n" "201 К. [С точки] Chocola - Aoi Teshima-Niji №\n" "202 DGJ. [С точки] Kaoru, Родя Светлов - Hetalia №35\n" "204 DGJ. [Неизвестно] Areshek - Предательство знает мое имя №89\n" "206 V. [Сразу~] JuliaValter - Если б я могла, то распустила б паруса (Shiki) №111\n" "208 T. [С точки] LDA - BTS-Blood, Sweat and Fire №177\n" "209 INK. [Неизвестно] Utakata - Taro Umebayashi-Yuri on ICE №65\n" "210 DSO. [Сразу] Molli - Принцесса Белоснежка №161\n" "212 DSO. [С точки] Ayumi Aozora - Loreen-Колибри №128\n" "214 DU. [Сразу] Infernal Princess - Сатир №85\n" "216 DU. [Сразу] Лисичка Цай-Шэн - Стрелец №119\n" "218 DU. [Сразу] Orokamonogatari - Fridgell - Кицунэ №152\n" "220 DU. [Сразу] Todji - Хацуюмэ №79\n" "224 DSE. [Сразу] Yami mr.Pingvi - Rise of the Guardians №202\n" "226 DSE. [Сразу] Bast[et] - Marvel Comics (Black Cat) №93\n" "228 V. [Сразу~] ALESSA - Good bye my friend №39\n" "230 KA. [С точки] Олег Кот - ONE OK ROCK-Heartache №195\n" "232 DSJ. [Сразу] sauronCat - Magi - The Labyrinth of Magic №6\n" "234 DSJ. [Сразу] Eva Heine - Герои Шести Цветов №183\n" "236 DSJ. [Сразу] Neko mimi - Sailor Moon №186\n" "238 DSJ. [Сразу] Umino Akari - Kami-sama Hajimemashita №94\n" "242 DSJ. [Сразу] Onii chan - Крестовый поход Хроно №165\n" "244 VC. [Сразу~] Step Up - Bleach - Bleach Live Opening №135\n" "246 DSG. [С точки] Ирина Лонер - League of Legends №134\n" "248 DSG. [Сразу] DisasterRus - Halo №185\n" "250 DSG. [Сразу] Paprika - Undertale №53\n" "252 DGG. [Сразу] JET SET - МАТЕО, Савич - Silent Hill №83\n" "254 DSG. [Сразу] Itami Liska - Fate Grand Order №51\n" "256 VC. [Сразу~] Fransuaza Stein - Scissors Crown - Alice №25\n" "258 T. [С точки] GLOOMY DANCE TEAM - BLACKPINK-Whistle+As If It's Your Last №109\n" "260 DGE. [Сразу] Конда, An Tiff - Tutenstein №127\n" "262 DGE. [С точки] Табун ежат - Джин-сама, Апекс - Samurai Jack №81\n" "264 DGE. [С точки] Alien frost, Pinky - Rise of the Guardians №7\n" "266 DGE. [Сразу] Black General, Murph - Atlantis - The Lost Empire №203\n" "268 KA. [Неизвестно] U - Shizuru Otaka-Natsu wo Mite Ita (OST Hotarubi no Mori e) №12\n" "270 V. [Сразу~] Neironezumi - ren'ai-kankei (Honobono Log) №144\n" "272 T. [С точки] Bread Ducks - Sistar-Shake it №36\n" "274 KA. [С точки] Patricia Heather, Юлия - Sound Horizon-Shinzou wo Sasageyo (Attack on Titan OP) №204\n" "302 DA. [Сразу] Ranmaru, Molli - Восточные сказки №162\n" "304 DA. [Сразу] Glitch Squad - Tora, Kim, Комар - Dota 2 №96\n" "306 K. [С точки] Just_Kurinai - u's-LOVELESS WORLD (OST Love Live! School Idol Project) №189\n" "308 V. [Сразу~] Kido - Life (Твоя апрельская ложь) №54\n" "310 T. [С точки] REDTeam - EXO-Monster №129\n" "312 KA. [Сразу] ТО Хикари - Ytakata, Konran - Lacrimosa-Kalafina (OST Kuroshitsuji) №191\n" "318 DSJ. [Сразу] Tenshi Neko - Dagashi Kashi (Магазинчик сладостей) №29\n" "320 DSJ. [Сразу] ALESSA - Haikyuu!! №46\n" "322 DSJ. [Сразу] Admiral Puni - D.N. Angel №187\n" "324 DSJ. [Сразу] Lenny - Shaman King №19\n" "326 DSJ. [Сразу] Mikki Moon - Tokyo Ghoul №68\n" "330 DU. [С точки] Bast[et] - Японский фольклор (Neko) №91\n" "332 DU. [Сразу] Fortune's Fool - Morana Virs, Суоди - Исо-онна, Фуна-юрэй №66\n" "334 DU. [Сразу] Molli - Кицунэ №159\n" "335 I. [Акайо! Сейчас!] Интермедия 9.3 - Гром №\n" "336 DGJ. [Сразу] Kroliczek - Neko_48, Fler, GEKATA - Алые сердца Корё №9\n" "340 DA. [Сразу] Missadefunctorum - Weyland, Куро Тачибано - Mejibray №174\n" "342 DA. [Сразу] Факел - Духи любят пошалить №95\n" "344 INK. [Неизвестно] U - Nao Hiiragi-Requiem (OST Tasogare Otome x Amnesia) №10\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