Regular Expressions 101

Save & Share

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

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

import re regex = re.compile(r".*?<Component>.*?<kind>district<\/kind>.*?<name>([^<]+)<\/name>.*", flags=re.DOTALL) test_str = ("<ymaps xmlns=\"http://maps.yandex.ru/ymaps/1.x\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/base/gml.xsd http://maps.yandex.ru/ymaps/1.x https://maps.yandex.ru/schemas/ymaps/1.x/ymaps.xsd http://maps.yandex.ru/geocoder/1.x http://maps.yandex.ru/schemas/geocoder/1.x/geocoder.xsd http://maps.yandex.ru/address/1.x http://maps.yandex.ru/schemas/search/1.x/address.xsd urn:oasis:names:tc:ciq:xsdschema:xAL:2.0 http://docs.oasis-open.org/election/external/xAL.xsd\">\n" "<GeoObjectCollection>\n" "<metaDataProperty xmlns=\"http://www.opengis.net/gml\">\n" "<GeocoderResponseMetaData xmlns=\"http://maps.yandex.ru/geocoder/1.x\">\n" "<request>56.751574,2038.573856</request>\n" "<found>3</found>\n" "<results>10</results>\n" "</GeocoderResponseMetaData>\n" "</metaDataProperty>\n" "<featureMember xmlns=\"http://www.opengis.net/gml\">\n" "<GeoObject xmlns=\"http://maps.yandex.ru/ymaps/1.x\" xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"1\">\n" "<metaDataProperty xmlns=\"http://www.opengis.net/gml\">\n" "<GeocoderMetaData xmlns=\"http://maps.yandex.ru/geocoder/1.x\">\n" "<kind>house</kind>\n" "<text>Турция, Сакарья, Хендек, Ени, улица 2038, 56</text>\n" "<precision>exact</precision>\n" "<Address xmlns=\"http://maps.yandex.ru/address/1.x\">\n" "<country_code>TR</country_code>\n" "<formatted>Турция, Сакарья, Хендек, Ени, улица 2038, 56</formatted>\n" "<Component>\n" "<kind>country</kind>\n" "<name>Турция</name>\n" "</Component>\n" "<Component>\n" "<kind>province</kind>\n" "<name>Сакарья</name>\n" "</Component>\n" "<Component>\n" "<kind>area</kind>\n" "<name>Хендек</name>\n" "</Component>\n" "<Component>\n" "<kind>district</kind>\n" "<name>Ени</name>\n" "</Component>\n" "<Component>\n" "<kind>street</kind>\n" "<name>улица 2038</name>\n" "</Component>\n" "<Component>\n" "<kind>house</kind>\n" "<name>56</name>\n" "</Component>\n" "</Address>\n" "<AddressDetails xmlns=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n" "<Country>\n" "<AddressLine>Турция, Сакарья, Хендек, Ени, улица 2038, 56</AddressLine>\n" "<CountryNameCode>TR</CountryNameCode>\n" "<CountryName>Турция</CountryName>\n" "<AdministrativeArea>\n" "<AdministrativeAreaName>Сакарья</AdministrativeAreaName>\n" "<SubAdministrativeArea>\n" "<SubAdministrativeAreaName>Хендек</SubAdministrativeAreaName>\n" "<Locality>\n" "<DependentLocality>\n" "<DependentLocalityName>Ени</DependentLocalityName>\n" "<Thoroughfare>\n" "<ThoroughfareName>улица 2038</ThoroughfareName>\n" "<Premise>\n" "<PremiseNumber>56</PremiseNumber>\n" "</Premise>\n" "</Thoroughfare>\n" "</DependentLocality>\n" "</Locality>\n" "</SubAdministrativeArea>\n" "</AdministrativeArea>\n" "</Country>\n" "</AddressDetails>\n" "</GeocoderMetaData>\n" "</metaDataProperty>\n" "<description xmlns=\"http://www.opengis.net/gml\">Ени, Хендек, Сакарья, Турция</description>\n" "<name xmlns=\"http://www.opengis.net/gml\">улица 2038, 56</name>\n" "<boundedBy xmlns=\"http://www.opengis.net/gml\">\n" "<Envelope>\n" "<lowerCorner>30.728833 40.789485</lowerCorner>\n" "<upperCorner>30.737043 40.795725</upperCorner>\n" "</Envelope>\n" "</boundedBy>\n" "<Point xmlns=\"http://www.opengis.net/gml\">\n" "<pos>30.732938 40.792605</pos>\n" "</Point>\n" "</GeoObject>\n" "</featureMember>\n" "<featureMember xmlns=\"http://www.opengis.net/gml\">\n" "<GeoObject xmlns=\"http://maps.yandex.ru/ymaps/1.x\" xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"2\">\n" "<metaDataProperty xmlns=\"http://www.opengis.net/gml\">\n" "<GeocoderMetaData xmlns=\"http://maps.yandex.ru/geocoder/1.x\">\n" "<kind>house</kind>\n" "<text>Турция, Денизли, Памуккале, Джанкуртаран, улица 2038, 56</text>\n" "<precision>exact</precision>\n" "<Address xmlns=\"http://maps.yandex.ru/address/1.x\">\n" "<country_code>TR</country_code>\n" "<formatted>Турция, Денизли, Памуккале, Джанкуртаран, улица 2038, 56</formatted>\n" "<Component>\n" "<kind>country</kind>\n" "<name>Турция</name>\n" "</Component>\n" "<Component>\n" "<kind>province</kind>\n" "<name>Денизли</name>\n" "</Component>\n" "<Component>\n" "<kind>area</kind>\n" "<name>Памуккале</name>\n" "</Component>\n" "<Component>\n" "<kind>district</kind>\n" "<name>Джанкуртаран</name>\n" "</Component>\n" "<Component>\n" "<kind>street</kind>\n" "<name>улица 2038</name>\n" "</Component>\n" "<Component>\n" "<kind>house</kind>\n" "<name>56</name>\n" "</Component>\n" "</Address>\n" "<AddressDetails xmlns=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n" "<Country>\n" "<AddressLine>Турция, Денизли, Памуккале, Джанкуртаран, улица 2038, 56</AddressLine>\n" "<CountryNameCode>TR</CountryNameCode>\n" "<CountryName>Турция</CountryName>\n" "<AdministrativeArea>\n" "<AdministrativeAreaName>Денизли</AdministrativeAreaName>\n" "<SubAdministrativeArea>\n" "<SubAdministrativeAreaName>Памуккале</SubAdministrativeAreaName>\n" "<Locality>\n" "<DependentLocality>\n" "<DependentLocalityName>Джанкуртаран</DependentLocalityName>\n" "<Thoroughfare>\n" "<ThoroughfareName>улица 2038</ThoroughfareName>\n" "<Premise>\n" "<PremiseNumber>56</PremiseNumber>\n" "</Premise>\n" "</Thoroughfare>\n" "</DependentLocality>\n" "</Locality>\n" "</SubAdministrativeArea>\n" "</AdministrativeArea>\n" "</Country>\n" "</AddressDetails>\n" "</GeocoderMetaData>\n" "</metaDataProperty>\n" "<description xmlns=\"http://www.opengis.net/gml\">Джанкуртаран, Памуккале, Денизли, Турция</description>\n" "<name xmlns=\"http://www.opengis.net/gml\">улица 2038, 56</name>\n" "<boundedBy xmlns=\"http://www.opengis.net/gml\">\n" "<Envelope>\n" "<lowerCorner>29.218953 37.67848</lowerCorner>\n" "<upperCorner>29.227164 37.685006</upperCorner>\n" "</Envelope>\n" "</boundedBy>\n" "<Point xmlns=\"http://www.opengis.net/gml\">\n" "<pos>29.223059 37.681743</pos>\n" "</Point>\n" "</GeoObject>\n" "</featureMember>\n" "<featureMember xmlns=\"http://www.opengis.net/gml\">\n" "<GeoObject xmlns=\"http://maps.yandex.ru/ymaps/1.x\" xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"3\">\n" "<metaDataProperty xmlns=\"http://www.opengis.net/gml\">\n" "<GeocoderMetaData xmlns=\"http://maps.yandex.ru/geocoder/1.x\">\n" "<kind>house</kind>\n" "<text>Турция, Адыяман, Адыяман Меркез, Сителер, улица 2038, 54</text>\n" "<precision>near</precision>\n" "<Address xmlns=\"http://maps.yandex.ru/address/1.x\">\n" "<country_code>TR</country_code>\n" "<formatted>Турция, Адыяман, Адыяман Меркез, Сителер, улица 2038, 54</formatted>\n" "<Component>\n" "<kind>country</kind>\n" "<name>Турция</name>\n" "</Component>\n" "<Component>\n" "<kind>province</kind>\n" "<name>Адыяман</name>\n" "</Component>\n" "<Component>\n" "<kind>area</kind>\n" "<name>Адыяман Меркез</name>\n" "</Component>\n" "<Component>\n" "<kind>district</kind>\n" "<name>Сителер</name>\n" "</Component>\n" "<Component>\n" "<kind>street</kind>\n" "<name>улица 2038</name>\n" "</Component>\n" "<Component>\n" "<kind>house</kind>\n" "<name>54</name>\n" "</Component>\n" "</Address>\n" "<AddressDetails xmlns=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n" "<Country>\n" "<AddressLine>Турция, Адыяман, Адыяман Меркез, Сителер, улица 2038, 54</AddressLine>\n" "<CountryNameCode>TR</CountryNameCode>\n" "<CountryName>Турция</CountryName>\n" "<AdministrativeArea>\n" "<AdministrativeAreaName>Адыяман</AdministrativeAreaName>\n" "<SubAdministrativeArea>\n" "<SubAdministrativeAreaName>Адыяман Меркез</SubAdministrativeAreaName>\n" "<Locality>\n" "<DependentLocality>\n" "<DependentLocalityName>Сителер</DependentLocalityName>\n" "<Thoroughfare>\n" "<ThoroughfareName>улица 2038</ThoroughfareName>\n" "<Premise>\n" "<PremiseNumber>54</PremiseNumber>\n" "</Premise>\n" "</Thoroughfare>\n" "</DependentLocality>\n" "</Locality>\n" "</SubAdministrativeArea>\n" "</AdministrativeArea>\n" "</Country>\n" "</AddressDetails>\n" "</GeocoderMetaData>\n" "</metaDataProperty>\n" "<description xmlns=\"http://www.opengis.net/gml\">Сителер, Адыяман Меркез, Адыяман, Турция</description>\n" "<name xmlns=\"http://www.opengis.net/gml\">улица 2038, 54</name>\n" "<boundedBy xmlns=\"http://www.opengis.net/gml\">\n" "<Envelope>\n" "<lowerCorner>38.291327 37.766104</lowerCorner>\n" "<upperCorner>38.299537 37.772622</upperCorner>\n" "</Envelope>\n" "</boundedBy>\n" "<Point xmlns=\"http://www.opengis.net/gml\">\n" "<pos>38.295432 37.769363</pos>\n" "</Point>\n" "</GeoObject>\n" "</featureMember>\n" "</GeoObjectCollection>\n" "</ymaps>") subst = "$1" result = regex.sub(subst, test_str) if result: print(result)

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