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

/
/
gs

Test String

Substitution

Processing...

Code Generator

Generated Code

re = /.*?<AddressLine>([^<]+)<\/AddressLine>.*/ 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"> <GeoObjectCollection> <metaDataProperty xmlns="http://www.opengis.net/gml"> <GeocoderResponseMetaData xmlns="http://maps.yandex.ru/geocoder/1.x"> <request>56.751574,2038.573856</request> <found>3</found> <results>10</results> </GeocoderResponseMetaData> </metaDataProperty> <featureMember xmlns="http://www.opengis.net/gml"> <GeoObject xmlns="http://maps.yandex.ru/ymaps/1.x" xmlns:gml="http://www.opengis.net/gml" gml:id="1"> <metaDataProperty xmlns="http://www.opengis.net/gml"> <GeocoderMetaData xmlns="http://maps.yandex.ru/geocoder/1.x"> <kind>house</kind> <text>Турция, Сакарья, Хендек, Ени, улица 2038, 56</text> <precision>exact</precision> <Address xmlns="http://maps.yandex.ru/address/1.x"> <country_code>TR</country_code> <formatted>Турция, Сакарья, Хендек, Ени, улица 2038, 56</formatted> <Component> <kind>country</kind> <name>Турция</name> </Component> <Component> <kind>province</kind> <name>Сакарья</name> </Component> <Component> <kind>area</kind> <name>Хендек</name> </Component> <Component> <kind>district</kind> <name>Ени</name> </Component> <Component> <kind>street</kind> <name>улица 2038</name> </Component> <Component> <kind>house</kind> <name>56</name> </Component> </Address> <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"> <Country> <AddressLine>Турция, Сакарья, Хендек, Ени, улица 2038, 56</AddressLine> <CountryNameCode>TR</CountryNameCode> <CountryName>Турция</CountryName> <AdministrativeArea> <AdministrativeAreaName>Сакарья</AdministrativeAreaName> <SubAdministrativeArea> <SubAdministrativeAreaName>Хендек</SubAdministrativeAreaName> <Locality> <DependentLocality> <DependentLocalityName>Ени</DependentLocalityName> <Thoroughfare> <ThoroughfareName>улица 2038</ThoroughfareName> <Premise> <PremiseNumber>56</PremiseNumber> </Premise> </Thoroughfare> </DependentLocality> </Locality> </SubAdministrativeArea> </AdministrativeArea> </Country> </AddressDetails> </GeocoderMetaData> </metaDataProperty> <description xmlns="http://www.opengis.net/gml">Ени, Хендек, Сакарья, Турция</description> <name xmlns="http://www.opengis.net/gml">улица 2038, 56</name> <boundedBy xmlns="http://www.opengis.net/gml"> <Envelope> <lowerCorner>30.728833 40.789485</lowerCorner> <upperCorner>30.737043 40.795725</upperCorner> </Envelope> </boundedBy> <Point xmlns="http://www.opengis.net/gml"> <pos>30.732938 40.792605</pos> </Point> </GeoObject> </featureMember> <featureMember xmlns="http://www.opengis.net/gml"> <GeoObject xmlns="http://maps.yandex.ru/ymaps/1.x" xmlns:gml="http://www.opengis.net/gml" gml:id="2"> <metaDataProperty xmlns="http://www.opengis.net/gml"> <GeocoderMetaData xmlns="http://maps.yandex.ru/geocoder/1.x"> <kind>house</kind> <text>Турция, Денизли, Памуккале, Джанкуртаран, улица 2038, 56</text> <precision>exact</precision> <Address xmlns="http://maps.yandex.ru/address/1.x"> <country_code>TR</country_code> <formatted>Турция, Денизли, Памуккале, Джанкуртаран, улица 2038, 56</formatted> <Component> <kind>country</kind> <name>Турция</name> </Component> <Component> <kind>province</kind> <name>Денизли</name> </Component> <Component> <kind>area</kind> <name>Памуккале</name> </Component> <Component> <kind>district</kind> <name>Джанкуртаран</name> </Component> <Component> <kind>street</kind> <name>улица 2038</name> </Component> <Component> <kind>house</kind> <name>56</name> </Component> </Address> <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"> <Country> <AddressLine>Турция, Денизли, Памуккале, Джанкуртаран, улица 2038, 56</AddressLine> <CountryNameCode>TR</CountryNameCode> <CountryName>Турция</CountryName> <AdministrativeArea> <AdministrativeAreaName>Денизли</AdministrativeAreaName> <SubAdministrativeArea> <SubAdministrativeAreaName>Памуккале</SubAdministrativeAreaName> <Locality> <DependentLocality> <DependentLocalityName>Джанкуртаран</DependentLocalityName> <Thoroughfare> <ThoroughfareName>улица 2038</ThoroughfareName> <Premise> <PremiseNumber>56</PremiseNumber> </Premise> </Thoroughfare> </DependentLocality> </Locality> </SubAdministrativeArea> </AdministrativeArea> </Country> </AddressDetails> </GeocoderMetaData> </metaDataProperty> <description xmlns="http://www.opengis.net/gml">Джанкуртаран, Памуккале, Денизли, Турция</description> <name xmlns="http://www.opengis.net/gml">улица 2038, 56</name> <boundedBy xmlns="http://www.opengis.net/gml"> <Envelope> <lowerCorner>29.218953 37.67848</lowerCorner> <upperCorner>29.227164 37.685006</upperCorner> </Envelope> </boundedBy> <Point xmlns="http://www.opengis.net/gml"> <pos>29.223059 37.681743</pos> </Point> </GeoObject> </featureMember> <featureMember xmlns="http://www.opengis.net/gml"> <GeoObject xmlns="http://maps.yandex.ru/ymaps/1.x" xmlns:gml="http://www.opengis.net/gml" gml:id="3"> <metaDataProperty xmlns="http://www.opengis.net/gml"> <GeocoderMetaData xmlns="http://maps.yandex.ru/geocoder/1.x"> <kind>house</kind> <text>Турция, Адыяман, Адыяман Меркез, Сителер, улица 2038, 54</text> <precision>near</precision> <Address xmlns="http://maps.yandex.ru/address/1.x"> <country_code>TR</country_code> <formatted>Турция, Адыяман, Адыяман Меркез, Сителер, улица 2038, 54</formatted> <Component> <kind>country</kind> <name>Турция</name> </Component> <Component> <kind>province</kind> <name>Адыяман</name> </Component> <Component> <kind>area</kind> <name>Адыяман Меркез</name> </Component> <Component> <kind>district</kind> <name>Сителер</name> </Component> <Component> <kind>street</kind> <name>улица 2038</name> </Component> <Component> <kind>house</kind> <name>54</name> </Component> </Address> <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"> <Country> <AddressLine>Турция, Адыяман, Адыяман Меркез, Сителер, улица 2038, 54</AddressLine> <CountryNameCode>TR</CountryNameCode> <CountryName>Турция</CountryName> <AdministrativeArea> <AdministrativeAreaName>Адыяман</AdministrativeAreaName> <SubAdministrativeArea> <SubAdministrativeAreaName>Адыяман Меркез</SubAdministrativeAreaName> <Locality> <DependentLocality> <DependentLocalityName>Сителер</DependentLocalityName> <Thoroughfare> <ThoroughfareName>улица 2038</ThoroughfareName> <Premise> <PremiseNumber>54</PremiseNumber> </Premise> </Thoroughfare> </DependentLocality> </Locality> </SubAdministrativeArea> </AdministrativeArea> </Country> </AddressDetails> </GeocoderMetaData> </metaDataProperty> <description xmlns="http://www.opengis.net/gml">Сителер, Адыяман Меркез, Адыяман, Турция</description> <name xmlns="http://www.opengis.net/gml">улица 2038, 54</name> <boundedBy xmlns="http://www.opengis.net/gml"> <Envelope> <lowerCorner>38.291327 37.766104</lowerCorner> <upperCorner>38.299537 37.772622</upperCorner> </Envelope> </boundedBy> <Point xmlns="http://www.opengis.net/gml"> <pos>38.295432 37.769363</pos> </Point> </GeoObject> </featureMember> </GeoObjectCollection> </ymaps>' subst = '$1' result = str.gsub(re, subst) # Print the result of the substitution puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html