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

/
/
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"(?:\"text\":\s*\{\s*\"ja_JP\":\s*\"|\G(?<=\\n))([^\"]*?)(?:\"|\\n)" test_str = ("\"textList\": [\n" " {\n" " \"id\": 4,\n" " \"name\": \"modeselect\",\n" " \"folder\": true, \"children\": [\n" " {\n" " \"id\": 13,\n" " \"name\": \"Motion\",\n" " \"fontId\": 6,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Motion\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 12,\n" " \"name\": \"Story\",\n" " \"fontId\": 7,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Story\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 11,\n" " \"name\": \"Main_Character\",\n" " \"fontId\": 6,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Main Character\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 5,\n" " \"name\": \"Mode_select\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Mode Select\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 24,\n" " \"name\": \"Story_Mode\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Story Mode\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 25,\n" " \"name\": \"Battle_Mode\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Battle Mode\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 8297,\n" " \"name\": \"Dictionary\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Dictionary\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 46,\n" " \"name\": \"Z_desition\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Z key:OK\\nC key:Back\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 47,\n" " \"name\": \"back_to_the_title\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Back to the title?\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 51,\n" " \"name\": \"select_mode\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Select Mode\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 8298,\n" " \"name\": \"Go_to_the_Story_Mode\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Go to the Story Mode?\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 8299,\n" " \"name\": \"Go_to_the_Battle_Mode\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Go to the Battle Mode?\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 8300,\n" " \"name\": \"Go_to_the_Dictionary\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Go to the Dictionary?\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 48,\n" " \"name\": \"ok\",\n" " \"fontId\": 8,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"OK\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 49,\n" " \"name\": \"cancel\",\n" " \"fontId\": 8,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Cancel\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 7,\n" " \"name\": \"Story_outline\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"自由奔放で傲慢な魔族\\nであるアストリア。\\nアストリアは最近\\n地上に住まう種族の\\n殲滅に勤しんでいた。\\n次第に恐怖と畏れから\\n地上に住まう者達に名が\\n知れ渡り始めていた。\\nある日、アストリアの\\n元に面倒事が\\n持ち込まれる・・・\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 6,\n" " \"name\": \"character_name\",\n" " \"folder\": true, \"children\": [\n" " {\n" " \"id\": 8,\n" " \"name\": \"Astoria\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Astoria\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 19,\n" " \"name\": \"Test2_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Test2\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 20,\n" " \"name\": \"Test3_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Test3\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 21,\n" " \"name\": \"Test4_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Test4\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 22,\n" " \"name\": \"Test5_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Test5\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 23,\n" " \"name\": \"Test6_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Test6\" },\n" " \"folder\": false\n" " }\n" " ]\n" " },\n" " {\n" " \"id\": 9,\n" " \"name\": \"story_name\",\n" " \"folder\": true, \"children\": [\n" " {\n" " \"id\": 10,\n" " \"name\": \"Story1_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"1. 魔族娘の自由旅\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 14,\n" " \"name\": \"Story2_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"2. \" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 15,\n" " \"name\": \"Story3_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"3. \" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 16,\n" " \"name\": \"Story4_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"4. \" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 17,\n" " \"name\": \"Story5_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"5. \" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 18,\n" " \"name\": \"Story6_name\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"6. \" },\n" " \"folder\": false\n" " }\n" " ]\n" " }\n" " ]\n" " },\n" " {\n" " \"id\": 26,\n" " \"name\": \"stageselect\",\n" " \"folder\": true, \"children\": [\n" " {\n" " \"id\": 31,\n" " \"name\": \"Stage_select\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Stage Select\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 32,\n" " \"name\": \"GameStart\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Game Start\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 33,\n" " \"name\": \"Enemy_Character\",\n" " \"fontId\": 6,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Enemy Character\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 50,\n" " \"name\": \"back_to_the_modeselect\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"Back to the Mode Select?\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 27,\n" " \"name\": \"character_name_stage\",\n" " \"folder\": true, \"children\": [\n" " {\n" " \"id\": 34,\n" " \"name\": \"Leonor\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Leonor\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 35,\n" " \"name\": \"Riz\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Riz\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 36,\n" " \"name\": \"Mary\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Mary\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 37,\n" " \"name\": \"Koyo\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Koyo\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 38,\n" " \"name\": \"Beryl\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Beryl\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 39,\n" " \"name\": \"Amelia\",\n" " \"fontId\": 5,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \" Amelia\" },\n" " \"folder\": false\n" " }\n" " ]\n" " },\n" " {\n" " \"id\": 28,\n" " \"name\": \"stage_outline\",\n" " \"folder\": true, \"children\": [\n" " {\n" " \"id\": 979,\n" " \"name\": \"stage1_outline\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"アストリアは日課である\\n種族の殲滅を終わらせて\\n城で休息を取っていた。\\nそんな時、何者かが城に\\n侵入した事を察知する。\\n急ぎ様子を見に行くと\\nそこには興味深そうに\\n城を見渡す堕天使の\\nレオノールが居た・・・\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 980,\n" " \"name\": \"stage2_outline\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"レオノールから\\n聞き出した情報を頼りに\\n妖狐を探していた。\\nその最中、魔族のリズが\\n道の真ん中で風景画を\\n描いているのを見かける\\n興味本位で声を掛け\\n描いている絵を見せて\\nもらったのだが・・・\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 981,\n" " \"name\": \"stage3_outline\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"ジメジメと湿った空気が\\n充満している薄暗い\\n森の中を進んでいると\\n奇妙な帽子を被った\\n魔女のメアリーが\\nアストリアの前に\\n立ち塞がる。\\n妖狐の差し金で\\nアストリアの邪魔を\\nしようとするが・・・\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 982,\n" " \"name\": \"stage4_outline\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"森を抜けた先に\\n古びた神社を見つけた\\nアストリア。\\n中から九つの白い尾を\\n持った妖狐の狐耀が\\n現れる。\\nアストリアと狐耀は\\n自身の主張を通すべく\\n力尽くで相手を屈服\\nさせようとする・・・\" },\n" " \"folder\": false\n" " },\n" " {\n" " \"id\": 983,\n" " \"name\": \"stage5_outline\",\n" " \"fontId\": 9,\n" " \"letterSpacing\": 0,\n" " \"lineSpacing\": 0,\n" " \"text\": { \"ja_JP\": \"面倒事を終わらせて\\n気が晴れたアストリアに\\n竜人種のベリルが声を\\n掛けてくる。\\nアストリアが狐耀を\\n倒したことに対して\\nベリルは感謝を示す。\\nどうでも良い\\nアストリアは休むべく\\n帰ろうとするが・・・\" },\n" " \"folder\": false") 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