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
No Match

/
/
gmui

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "([ぁ-ゟ])"; final String string = "Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!\n" + "([一-龯])\n\n" + "Regex for matching Hirgana or Katakana\n" + "([ぁ-んァ-ン])\n\n" + "Regex for matching Non-Hirgana or Non-Katakana\n" + "([^ぁ-んァ-ン])\n\n" + "Regex for matching Hirgana or Katakana or basic punctuation (、。’)\n" + "([ぁ-んァ-ン\\w])\n\n" + "Regex for matching Hirgana or Katakana and random other characters\n" + "([ぁ-んァ-ン!:/])\n\n" + "Regex for matching Hirgana\n" + "([ぁ-ん])\n\n" + "Regex for matching full-width Katakana (zenkaku 全角)\n" + "([ァ-ン])\n\n" + "Regex for matching half-width Katakana (hankaku 半角)\n" + "([ァ-ン゙゚])\n\n" + "Regex for matching full-width Numbers (zenkaku 全角)\n" + "([0-9])\n\n" + "Regex for matching full-width Letters (zenkaku 全角)\n" + "([A-z])\n\n" + "Regex for matching Hiragana codespace characters (includes non phonetic characters)\n" + "([ぁ-ゞ])\n\n" + "Regex for matching full-width (zenkaku) Katakana codespace characters (includes non phonetic characters)\n" + "([ァ-ヶ])\n\n" + "Regex for matching half-width (hankaku)\n" + "Katakana codespace characters (this is an old character set so the order is inconsistent with the hiragana)\n" + "([ヲ-゚])\n\n" + "Regex for matching Japanese Post Codes\n" + "/^¥d{3}¥-¥d{4}$/\n" + "/^¥d{3}-¥d{4}$|^¥d{3}-¥d{2}$|^¥d{3}$/\n\n" + "Regex for matching Japanese mobile phone numbers (keitai bangou)\n" + "/^¥d{3}-¥d{4}-¥d{4}$|^¥d{11}$/\n" + "/^0¥d0-¥d{4}-¥d{4}$/\n\n" + "Regex for matching Japanese fixed line phone numbers\n" + "/^[0-9-]{6,9}$|^[0-9-]{12}$/\n" + "/^¥d{1,4}-¥d{4}$|^¥d{2,5}-¥d{1,4}-¥d{4}$/\n\n" + "Match all English alphanumerics, Japanese katakana,hiragana,multibytes of alphanumerics [hankaku and zenkaku],dashes\n" + "/[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+|[a-zA-Z0-9]+|[a-zA-Z0-9]+[々〆〤]+/u\n" + "========================================================\n" + "--------------------------------------------------------\n" + "Half-width alphanumeric characters\n" + "([!-~])\n\n" + "!\"#$%&'()*+,-./0123456789:;<=>?\n" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\n" + "`abcdefghijklmnopqrstuvwxyz{|}~€\n\n" + "--------------------------------------------------------\n" + "Half-width KANA (hard)\n\n" + "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソ\n" + "タチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚\n\n" + "--------------------------------------------------------\n" + "Full-width alphanumeric characters\n\n" + "0123456789\n" + "ABCDEFGHIJKLMNOP\n" + "QRSTUVWXYZabcdef\n" + "ghijklmnopqrstuv\n" + "wxyz\n\n" + "--------------------------------------------------------\n" + "full-width KANA (soft)\n\n" + "ぁあぃいぅうぇえぉおかがきぎくぐ\n" + "けげこごさざしじすずせぜそぞただ\n" + "ちぢっつづてでとどなにぬねのはば\n" + "ぱひびぴふぶぷへべぺほぼぽまみむ\n" + "めもゃやゅゆょよらりるれろゎわゐ\n" + "ゑをん\n\n" + "--------------------------------------------------------\n" + "full-width KANA (hard)\n\n" + "ァアィイゥウェエォオカガキギクグ\n" + "ケゲコゴサザシジスズセゼソゾタダ\n" + "チヂッツヅテデトドナニヌネノハバ\n" + "パヒビピフブプヘベペホボポマミム\n" + "メモャヤュユョヨラリルレロヮワヰ\n" + "ヱヲンヴヵヶ\n\n" + "--------------------------------------------------------\n" + "Symbol\n\n" + "、。,.・:;?!゛゜´`¨^ ̄\n" + "_ヽヾゝゞ〃仝々〆〇ー―‐/\~\n" + "∥|…‥‘’“”()〔〕[]{}\n" + "〈〉《》「」『』【】+-±×÷=\n" + "≠<>≦≧∞∴♂♀°′″℃¥$¢\n" + "£%#&*@§☆★○●◎◇◆□■\n" + "△▲▽▼※〒→←↑↓〓∈∋⊆⊇⊂\n" + "⊃∪∩∧∨¬⇒⇔∀∃∠⊥⌒∂∇≡\n" + "≒≪≫√∽∝∵∫∬ʼn♯♭♪\n" + "---------------------------------------------------------\n\n" + "Hiragana\n" + "Unicode code points regex: [\\x3041-\\x3096]\n" + "Unicode block property regex: \\p{Hiragana}\n" + "Regex: ([ぁ-ゟ])\n\n\n" + "ぁ あ ぃ い ぅ う ぇ え ぉ お か が き ぎ く ぐ け げ こ ご さ ざ し じ す ず せ ぜ そ ぞ た だ ち ぢ っ つ づ て で と ど な に ぬ ね の は ば ぱ ひ び ぴ ふ ぶ ぷ へ べ ぺ ほ ぼ ぽ ま み む め も ゃ や ゅ ゆ ょ よ ら り る れ ろ ゎ わ ゐ ゑ を ん ゔ ゕ ゖ ゙ ゚ ゛ ゜ ゝ ゞ ゟ\n" + "---------------------------------------------------------\n" + "Katakana (Full Width)\n" + "Unicode code points regex: [\\x30A0-\\x30FF]\n" + "Unicode block property regex: \\p{Katakana}\n" + "([ァ-ヿ])\n\n" + "゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ\n" + "---------------------------------------------------------\n" + "Kanji\n" + "Unicode code points regex: [\\x3400-\\x4DB5\\x4E00-\\x9FCB\\xF900-\\xFA6A]\n" + "Unicode block property regex: \\p{Han}\n" + "Regex: ([㐀-䶵一-鿋豈-頻])\n\n" + "漢字 日本語 文字 言語 言葉 etc. Too many characters to list.\n\n" + "This regular expression will match all the kanji, including those used in Chinese.\n" + "---------------------------------------------------------\n" + "Kanji Radicals\n" + "Unicode code points regex: [\\x2E80-\\x2FD5]\n" + "Regex: ([⺀-⿕])\n\n" + "⺀ ⺁ ⺂ ⺃ ⺄ ⺅ ⺆ ⺇ ⺈ ⺉ ⺊ ⺋ ⺌ ⺍ ⺎ ⺏ ⺐ ⺑ ⺒ ⺓ ⺔ ⺕ ⺖ ⺗ ⺘ ⺙ ⺚ ⺛ ⺜ ⺝ ⺞ ⺟ ⺠ ⺡ ⺢ ⺣ ⺤ ⺥ ⺦ ⺧ ⺨ ⺩ ⺪ ⺫ ⺬ ⺭ ⺮ ⺯ ⺰ ⺱ ⺲ ⺳ ⺴ ⺵ ⺶ ⺷ ⺸ ⺹ ⺺ ⺻ ⺼ ⺽ ⺾ ⺿ ⻀ ⻁ ⻂ ⻃ ⻄ ⻅ ⻆ ⻇ ⻈ ⻉ ⻊ ⻋ ⻌ ⻍ ⻎ ⻏ ⻐ ⻑ ⻒ ⻓ ⻔ ⻕ ⻖ ⻗ ⻘ ⻙ ⻚ ⻛ ⻜ ⻝ ⻞ ⻟ ⻠ ⻡ ⻢ ⻣ ⻤ ⻥ ⻦ ⻧ ⻨ ⻩ ⻪ ⻫ ⻬ ⻭ ⻮ ⻯ ⻰ ⻱ ⻲ ⻳\n" + "⼀ ⼁ ⼂ ⼃ ⼄ ⼅ ⼆ ⼇ ⼈ ⼉ ⼊ ⼋ ⼌ ⼍ ⼎ ⼏ ⼐ ⼑ ⼒ ⼓ ⼔ ⼕ ⼖ ⼗ ⼘ ⼙ ⼚ ⼛ ⼜ ⼝ ⼞ ⼟ ⼠ ⼡ ⼢ ⼣ ⼤ ⼥ ⼦ ⼧ ⼨ ⼩ ⼪ ⼫ ⼬ ⼭ ⼮ ⼯ ⼰ ⼱ ⼲ ⼳ ⼴ ⼵ ⼶ ⼷ ⼸ ⼹ ⼺ ⼻ ⼼ ⼽ ⼾ ⼿ ⽀ ⽁ ⽂ ⽃ ⽄ ⽅ ⽆ ⽇ ⽈ ⽉ ⽊ ⽋ ⽌ ⽍ ⽎ ⽏ ⽐ ⽑ ⽒ ⽓ ⽔ ⽕ ⽖ ⽗ ⽘ ⽙ ⽚ ⽛ ⽜ ⽝ ⽞ ⽟ ⽠ ⽡ ⽢ ⽣ ⽤ ⽥ ⽦ ⽧ ⽨ ⽩ ⽪ ⽫ ⽬ ⽭ ⽮ ⽯ ⽰ ⽱ ⽲ ⽳ ⽴ ⽵ ⽶ ⽷ ⽸ ⽹ ⽺ ⽻ ⽼ ⽽ ⽾ ⽿ ⾀ ⾁ ⾂ ⾃ ⾄ ⾅ ⾆ ⾇ ⾈ ⾉ ⾊ ⾋ ⾌ ⾍ ⾎ ⾏ ⾐ ⾑ ⾒ ⾓ ⾔ ⾕ ⾖ ⾗ ⾘ ⾙ ⾚ ⾛ ⾜ ⾝ ⾞ ⾟ ⾠ ⾡ ⾢ ⾣ ⾤ ⾥ ⾦ ⾧ ⾨ ⾩ ⾪ ⾫ ⾬ ⾭ ⾮ ⾯ ⾰ ⾱ ⾲ ⾳ ⾴ ⾵ ⾶ ⾷ ⾸ ⾹ ⾺ ⾻ ⾼ ⾽ ⾾ ⾿ ⿀ ⿁ ⿂ ⿃ ⿄ ⿅ ⿆ ⿇ ⿈ ⿉ ⿊ ⿋ ⿌ ⿍ ⿎ ⿏ ⿐ ⿑ ⿒ ⿓ ⿔ ⿕\n" + "---------------------------------------------------------\n" + "Katakana and Punctuation (Half Width)\n" + "Unicode code points regex: [\\xFF5F-\\xFF9F]\n" + "Regex: ([⦅-ン])\n\n" + "⦅ ⦆ 。 「 」 、 ・ ヲ ァ ィ ゥ ェ ォ ャ ュ ョ ッ ー ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン ゙\n" + "---------------------------------------------------------\n" + "Japanese Symbols and Punctuation\n" + "Unicode code points regex: [\\x3000-\\x303F]\n" + "Regex: ([、-〿])\n\n" + "、 。 〃 〄 々 〆 〇 〈 〉 《 》 「 」 『 』 【 】 〒 〓 〔 〕 〖 〗 〘 〙 〚 〛 〜 〝 〞 〟 〠 〡 〢 〣 〤 〥 〦 〧 〨 〩 〪 〫 〬 〭 〮 〯 〰 〱 〲 〳 〴 〵 〶 〷 〸 〹 〺 〻 〼 〽 〾 〿\n" + "---------------------------------------------------------\n" + "Miscellaneous Japanese Symbols and Characters\n" + "Unicode code points regex: ([\\x31F0-\\x31FF\\x3220-\\x3243\\x3280-\\x337F])\n" + "Regex: ([ㇰ-ㇿ㈠-㉃㊀-㍿])\n\n" + "ㇰ ㇱ ㇲ ㇳ ㇴ ㇵ ㇶ ㇷ ㇸ ㇹ ㇺ ㇻ ㇼ ㇽ ㇾ ㇿ\n" + "㈠ ㈡ ㈢ ㈣ ㈤ ㈥ ㈦ ㈧ ㈨ ㈩ ㈪ ㈫ ㈬ ㈭ ㈮ ㈯ ㈰ ㈱ ㈲ ㈳ ㈴ ㈵ ㈶ ㈷ ㈸ ㈹ ㈺ ㈻ ㈼ ㈽ ㈾ ㈿ ㉀ ㉁ ㉂ ㉃\n" + "㊀ ㊁ ㊂ ㊃ ㊄ ㊅ ㊆ ㊇ ㊈ ㊉ ㊊ ㊋ ㊌ ㊍ ㊎ ㊏ ㊐ ㊑ ㊒ ㊓ ㊔ ㊕ ㊖ ㊗ ㊘ ㊙ ㊚ ㊛ ㊜ ㊝ ㊞ ㊟ ㊠ ㊡ ㊢ ㊣ ㊤ ㊥ ㊦ ㊧ ㊨ ㊩ ㊪ ㊫ ㊬ ㊭ ㊮ ㊯ ㊰ ㊱ ㊲ ㊳ ㊴ ㊵ ㊶ ㊷ ㊸ ㊹ ㊺ ㊻ ㊼ ㊽ ㊾ ㊿\n" + "㋀ ㋁ ㋂ ㋃ ㋄ ㋅ ㋆ ㋇ ㋈ ㋉ ㋊ ㋋ ㋐ ㋑ ㋒ ㋓ ㋔ ㋕ ㋖ ㋗ ㋘ ㋙ ㋚ ㋛ ㋜ ㋝ ㋞ ㋟ ㋠ ㋡ ㋢ ㋣ ㋤ ㋥ ㋦ ㋧ ㋨ ㋩ ㋪ ㋫ ㋬ ㋭ ㋮ ㋯ ㋰ ㋱ ㋲ ㋳ ㋴ ㋵ ㋶ ㋷ ㋸ ㋹ ㋺ ㋻ ㋼ ㋽ ㋾\n" + "㌀ ㌁ ㌂ ㌃ ㌄ ㌅ ㌆ ㌇ ㌈ ㌉ ㌊ ㌋ ㌌ ㌍ ㌎ ㌏ ㌐ ㌑ ㌒ ㌓ ㌔ ㌕ ㌖ ㌗ ㌘ ㌙ ㌚ ㌛ ㌜ ㌝ ㌞ ㌟ ㌠ ㌡ ㌢ ㌣ ㌤ ㌥ ㌦ ㌧ ㌨ ㌩ ㌪ ㌫ ㌬ ㌭ ㌮ ㌯ ㌰ ㌱ ㌲ ㌳ ㌴ ㌵ ㌶ ㌷ ㌸ ㌹ ㌺ ㌻ ㌼ ㌽ ㌾ ㌿ ㍀ ㍁ ㍂ ㍃ ㍄ ㍅ ㍆ ㍇ ㍈ ㍉ ㍊ ㍋ ㍌ ㍍ ㍎ ㍏ ㍐ ㍑ ㍒ ㍓ ㍔ ㍕ ㍖ ㍗ ㍘ ㍙ ㍚ ㍛ ㍜ ㍝ ㍞ ㍟ ㍠ ㍡ ㍢ ㍣ ㍤ ㍥ ㍦ ㍧ ㍨ ㍩ ㍪ ㍫ ㍬ ㍭ ㍮ ㍯ ㍰ ㍱ ㍲ ㍳ ㍴ ㍵ ㍶ ㍻ ㍼ ㍽ ㍾ ㍿\n" + "---------------------------------------------------------\n" + "Alphanumeric and Punctuation (Full Width)\n" + "Unicode code points regex: [\\xFF01-\\xFF5E]\n" + "Regex: ([!-~])\n\n\n" + "! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?\n" + "@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _\n" + "` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~\n" + "---------------------------------------------------------\n" + " \n\n\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html