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

/
/
msg

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"(?:Характеристики\"\]\n*)(?<description>[^\[]*)\n" test_str = ("[et_pb_section admin_label=\"section\" fullwidth=\"off\" specialty=\"on\" background_color=\"#ffffff\" inner_shadow=\"off\" parallax=\"off\" parallax_method=\"css\" module_class=\"project-page\"][et_pb_column type=\"3_4\" specialty_columns=\"3\"][et_pb_row_inner admin_label=\"row_inner\"][et_pb_column_inner type=\"4_4\" saved_specialty_column_type=\"3_4\"][et_pb_text admin_label=\"Text\" background_layout=\"light\" text_orientation=\"left\" module_class=\"project-page1\"]\n\n" "<span style=\"font-size: 1.7em; font-weight: bold;\">Проект \"Галыч\" 128,28 м.кв.</span>\n\n" "[/et_pb_text][/et_pb_column_inner][/et_pb_row_inner][et_pb_row_inner admin_label=\"row_inner\"][et_pb_column_inner type=\"1_2\" saved_specialty_column_type=\"3_4\"][et_pb_image admin_label=\"Image\" src=\"http://servus.km.ua/wp-content/gallery/galych/galych.jpg?i=1297278904\" show_in_lightbox=\"off\" url_new_window=\"off\" animation=\"off\" module_class=\"project-page\"] [/et_pb_image][/et_pb_column_inner][et_pb_column_inner type=\"1_2\" saved_specialty_column_type=\"3_4\"][et_pb_text admin_label=\"Project CTA\" background_layout=\"dark\" text_orientation=\"left\" module_class=\"project-page\"]\n" "<div class=\"project-cta\">\n" "<div class=\"project-cta-title1\">Узнайте стоимость строительства!</div>\n" "<div class=\"project-cta-text\"><center>[contact-form-7 id=\"6802\" title=\"Просчет проекта\"]</center></div>\n" "</div>\n" "[/et_pb_text][/et_pb_column_inner][/et_pb_row_inner][et_pb_row_inner admin_label=\"row_inner\"][et_pb_column_inner type=\"4_4\" saved_specialty_column_type=\"3_4\"][et_pb_accordion admin_label=\"Accordion\" module_class=\"ac-top\"] [et_pb_accordion_item title=\"Характеристики\"]\n\n" "Двухэтажный дом с просторной террасой. Просторные комнаты, несмотря на малую площадь дома. Прекрасно подойдет для небольшой семьи или дачного дома.\n\n" "[/et_pb_accordion_item][et_pb_accordion_item title=\"Технология\"]\n\n" "<span style=\"color: #666666;\"><strong>Фундамент</strong> — монолитный ж/б</span><br style=\"color: #666666;\" /><span style=\"color: #666666;\"><strong>Несущие стены</strong> — SIP панель (164мм)</span><br style=\"color: #666666;\" /><span style=\"color: #666666;\"><strong>Перекрытия</strong> — деревянные двутавровые балки</span><br style=\"color: #666666;\" /><span style=\"color: #666666;\"><strong>Покрытие</strong> — битумная или металлочерепица</span><br style=\"color: #666666;\" /><span style=\"color: #666666;\"><strong>Наружная отделка</strong> — штукатурка, облицовочная плитка, природный камень</span>\n\n" "[/et_pb_accordion_item] [/et_pb_accordion][et_pb_tabs admin_label=\"Tabs\" tab_font_size=\"14\" body_font_size=\"14\" use_border_color=\"off\" border_color=\"#ffffff\" border_style=\"solid\"] [et_pb_tab title=\"Этажные планы\" tab_font_select=\"default\" body_font_select=\"default\"]\n\n" "<img src=\"http://servus.km.ua/wp-content/gallery/galych/1store.jpg?i=1483016512\" alt=\"\" />\n\n" "<b>Габариты дома:</b> 7.48м х 10.69м\n\n" "ПЛАН ПЕРВОГО ЭТАЖА*\n" "1. Терраса 12.99м2\n" "2. Гостиная 24.71м2\n" "3. Кухня 6,88м2\n" "4. Хол 4,62м2\n" "5. Коридор 4,20м2\n" "6. Прихожая 1,55м2\n" "7. Кабинет 9,05м2\n" "7. Терраса 11,22м2\n\n" "*наши архитекторы могут изменить планировку по Вашему желанию <span style=\"color: #ff0000; font-size: 1.1em; text-decoration: underline; font-weight: bold;\">БЕСПЛАТНО</span>\n\n" "<img src=\"http://servus.km.ua/wp-content/gallery/galych/2store.jpg?i=1855892229\" alt=\"\" />\n\n" "ПЛАН ВТОРОГО ЭТАЖА*\n" "1. Балкон 12.99м2\n" "2. Спальня 11.86м2\n" "3. Коридор 1,31м2\n" "4. Спальня 15,68м2\n" "5. Балкон 11,22м2\n\n" "*наши архитекторы могут изменить планировку по Вашему желанию <span style=\"color: #ff0000; font-size: 1.1em; text-decoration: underline; font-weight: bold;\">БЕСПЛАТНО</span>\n\n" "[/et_pb_tab][et_pb_tab title=\"Фасады\" tab_font_select=\"default\" body_font_select=\"default\"]\n\n" "<img src=\"http://servus.km.ua/wp-content/gallery/galych/fasad1.jpg?i=1221828987\" alt=\"\" />  <img src=\"http://servus.km.ua/wp-content/gallery/galych/fasad2.jpg?i=648025905\" alt=\"\" /> <img src=\"http://servus.km.ua/wp-content/gallery/galych/fasad3.jpg?i=1573804814\" alt=\"\" />  <img src=\"http://servus.km.ua/wp-content/gallery/galych/fasad4.jpg?i=1604215263\" alt=\"\" />\n\n" "&nbsp;\n\n" "&nbsp;\n\n" "[/et_pb_tab][et_pb_tab title=\"Фото готового дома\"] Проект еще не построен, или находится на стадии строительства [/et_pb_tab] [/et_pb_tabs][/et_pb_column_inner][/et_pb_row_inner][/et_pb_column][et_pb_column type=\"1_4\"][et_pb_text admin_label=\"Европейский сертификат\" background_layout=\"light\" text_orientation=\"left\" module_class=\"project-page1\"]\n" "<p style=\"text-align: center;\"><img class=\"wp-image-3276 size-full\" style=\"margin-left: 3px; margin-right: 3px; float: left;\" src=\"http://servus.km.ua/wp-content/uploads/eu_logo.jpg\" alt=\"eu_logo\" width=\"100\" height=\"64\" /><span style=\"font-size: 1.2em; font-weight: bold; line-height: 1.3em;\">Европейский сертификат</span> <a title=\"Посмотреть сертификат\" href=\"http://servus.km.ua/o-kompanii/sertifikatyi\">Посмотреть</a> <span style=\"font-size: 1.1em;\">Строим в Украине и Европе по европейским стандартам</span></p>\n" "[/et_pb_text][et_pb_text admin_label=\"Text\" background_layout=\"light\" text_orientation=\"left\"] <a class=\"button-help\" style=\"color: #ffffff; font-weight: bold;\" href=\"http://servus.km.ua/project/podbor-proekta-po-parametram\"><span style=\"margin: 0 auto;\">Помочь с выбором проекта?</span></a> [/et_pb_text][et_pb_text admin_label=\"Реализованные проекты\" background_layout=\"light\" text_orientation=\"left\" module_class=\"project-page-top project-page-bottom\"]\n" "<p style=\"text-align: center; font-size: 1.2em;\"><strong>Реализованные проекты</strong></p>\n" "[/et_pb_text][et_pb_slider admin_label=\"Slider\" show_arrows=\"on\" show_pagination=\"off\" auto=\"on\" ") matches = re.finditer(regex, test_str, re.MULTILINE | re.DOTALL) 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