Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • 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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

"
"
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?<pref>京都府)?\s*(?<city>京都市)\s*(?<ward>[上中下左右]京区|東山区|南区)\s*(?<street>(?!太秦安井柳通町|嵯峨中通町)(?:(?:[一-龠々ぁ-んァ-ンノ]+(?:通|筋|小路)|[一二三四五六七八九十百千]+(?:筋|本)目|[一二三四五六七八九十百千]+丁目|[東西南北]入(?:[るルル])?|[東西南北](?:裏|側)|[上下](?!丸屋町|材木町|柳町)(?:[るルル]|がる)?|[一-龠々ぁ-んァ-ンノ]+(?=\s*(?:[東西南北]入|[上下](?:[るルル]|がる)?)))\s*)+)?(?<town>.+)"; string substitution = @"${pref}${city}${ward}${town}"; string input = @"京都府京都市上京区室町通一条上る小島町123-4 京都府京都市上京区今出川通室町西入ル紙屋川町345-5 京都府京都市上京区新町通丸太町下る春帯町678-6 京都府京都市中京区烏丸通御池下る饅頭屋町789-7 京都府京都市中京区三条通河原町東入ル中島町101-8 京都府京都市中京区御幸町通錦小路上ル船屋町202-9 京都府京都市中京区麸屋町通六角下る坂井町303-10 京都府京都市下京区四条通柳馬場西入ル立売西町404-11 京都府京都市下京区松原通西洞院東入ル本塩竈町505-12 京都府京都市下京区花屋町通松原上る柿本町606-13 京都府京都市左京区東大路通仁王門下る東門前町707-14 京都府京都市左京区北大路通下鴨本通西入ル下鴨前萩町808-15 京都府京都市左京区白川通今出川上る石橋町909-16 京都府京都市右京区西大路通御池下る西小路町111-17 京都府京都市上京区大宮通寺之内上る二丁目西入社横町288 京都府京都市上京区大宮通寺之内下る花開院町126 京都府京都市中京区寺町通三条上る天性寺前町535 京都府京都市下京区烏丸通七条下る東塩小路町590−2 京都府京都市中京区寺町通六角上る桜之町426番地 京都府京都市下京区四条通室町東入函谷鉾町78番地 京都府京都市上京区上ノ下立売通紙屋川東入堀川町527−26 京都府京都市東山区鞘町通正面下る上堀詰町265 京都府京都市下京区松原通西洞院東入藪下町2 京都府京都市下京区東中筋通花屋町下る柳町335−3 京都府京都市下京区東洞院通四条下る元悪王子町47−4 京都市中京区河原町通姉小路上ル下丸屋町408 京都市下京区木屋町五条上がる下材木町 447 京都府京都市右京区太秦安井柳通町1-1番地の4 京都府京都市右京区嵯峨中通町1-1番地の4 京都府京都市下京区六条通烏丸西入上柳町1-1番地の4 京都府京都市上京区中筋通智恵光院西入菱屋町1-1番地の4 "; RegexOptions options = RegexOptions.Multiline; Regex regex = new Regex(pattern, options); string result = regex.Replace(input, 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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx