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

r"
"
gm

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 = "(?:[A-Z]{2} \\d{6}(?!\\d)|(?<!\\S)\\d{4,}(?!\\S))"; final String string = "1st Prize Rs :120000000/- 1) XG 218582 (KOTTAYAM)\n" + "Cons Prize-Rs :500000/- XA 218582XB 218582XC 218582XD 218582XE 218582\n" + "2nd Prize Rs :5000000/- 1) XA 788417 (THRISSUR)\n" + "2) XB 161796 (ADIMALY)\n" + "3) XC 319503 (ATTINGAL)\n" + "4) XD 713832 (KOTTAYAM)\n" + "5) XE 667708 (KOTTAYAM)\n" + "6) XG 137764 (NEYYATTINKARA)\n" + "3rd Prize Rs :1000000/- 1) XA 787512 (THRISSUR)\n" + "2) XB 771674 (WAYANADU)\n" + "3) XC 159927 (PALAKKAD)\n" + "4) XD 261430 (ERNAKULAM)\n" + "5) XE 632559 (THIRUR)\n" + "6) XG 232661 (KOLLAM)\n" + "4th Prize Rs :500000/- 1) XA 741906 (ATTINGAL)\n" + "2) XB 145409 (MANANTHAVADY)\n" + "3) XC 489704 (KARUNAGAPALLY)\n" + "4) XD 184478 (KOZHIKKODE)\n" + "5) XE 848905 (NEYYATTINKARA)\n" + "6) XG 839293 (KAYAMKULAM)\n" + "FOR THE TICKETS ENDING WITH THE FOLLOWING NUMBERS\n" + "5th Prize Rs :100000/- 1) 07225\n" + "16/01/2022 16:31:15 IT Support : NIC Kerala Page 1\n" + "2) 65420\n" + "6th Prize-Rs :5000/- 0274 0461 0836 1182 1862\n" + "1953 3116 3869 4355 4532\n" + "4630 4821 5478 5483 6292\n" + "6341 6449 6644 6884 6976\n" + "7313 8117 8229 8508 8692\n" + "8851 9060 9365 9595 9996\n" + "7th Prize-Rs :3000/- 1183 1416 1514 1994 2578\n" + "2858 2879 3115 3159 3270\n" + "3605 3624 4029 4114 4256\n" + "4327 4768 5074 5446 5676\n" + "5784 5921 6528 6552 6611\n" + "6664 6900 7576 7819 7998\n" + "8011 8918 8923 8929 9787\n" + "9974\n" + "8th Prize-Rs :2000/- 0095 0114 0422 0596 1086\n" + "1363 1492 2391 2411 2439\n" + "2716 2807 2850 3285 3399\n" + "3460 3559 3562 3828 4414\n" + "4632 4672 4812 5096 5158\n" + "5388 6913 7464 7626 7827\n" + "7841 8542 8717 9632 9703\n" + "9712\n" + "9th Prize-Rs :1000/- 0022 0076 0164 0237 0242\n" + "0307 0361 0364 0379 0438\n" + "0439 0452 0516 0544 0547\n" + "0577 0603 0647 0659 0680\n" + "0709 0742 0759 0789 0810\n" + "0859 0920 1060 1062 1090\n" + "16/01/2022 16:31:15 IT Support : NIC Kerala Page 2\n" + "1105 1126 1173 1181 1347\n" + "1389 1420 1448 1526 1667\n" + "1712 1775 1793 1821 1827\n" + "1874 1882 1942 1954 2026\n" + "2042 2054 2072 2074 2107\n" + "2115 2116 2150 2154 2207\n" + "2230 2318 2378 2387 2389\n" + "2490 2536 2586 2616 2656\n" + "2731 2835 2893 2921 2937\n" + "2953 2996 3049 3082 3131\n" + "3132 3147 3172 3179 3186\n" + "3196 3198 3235 3277 3324\n" + "3340 3355 3383 3392 3459\n" + "3467 3468 3522 3528 3545\n" + "3549 3581 3665 3666 3769\n" + "3850 3896 3911 3969 4056\n" + "4085 4094 4147 4154 4189\n" + "4326 4381 4537 4557 4582\n" + "4631 4667 4762 4770 4788\n" + "4820 4888 4928 4950 5020\n" + "5031 5198 5217 5244 5253\n" + "5271 5418 5427 5501 5549\n" + "5587 5698 5707 5717 5760\n" + "5763 5826 5827 5857 5923\n" + "5932 5958 5985 6046 6049\n" + "6057 6100 6171 6228 6287\n" + "6309 6347 6374 6378 6450\n" + "6483 6487 6529 6533 6568\n" + "6651 6662 6698 6715 6733\n" + "16/01/2022 16:31:16 IT Support : NIC Kerala Page 3\n" + "6763 6811 6891 6960 6971\n" + "6977 6979 7001 7037 7068\n" + "7105 7135 7157 7177 7216\n" + "7224 7447 7513 7540 7612\n" + "7675 7685 7717 7729 7814\n" + "7822 7823 7870 7876 7914\n" + "7921 7952 7964 8028 8120\n" + "8131 8141 8145 8151 8185\n" + "8195 8203 8228 8230 8238\n" + "8284 8304 8483 8614 8622\n" + "8623 8697 8839 8859 8860\n" + "8922 8979 9020 9026 9115\n" + "9135 9137 9140 9220 9297\n" + "9359 9364 9371 9456 9516\n" + "9529 9626 9664 9680 9701\n" + "9711 9836\n\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 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