Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

$re = '/^[0-9]+[a-z]{0,2}(\s\((IV|V?I{0,3})\))?$/m'; $str = '1 2 3 4 5 6 7 8 8a 8b 8c 8d 8e 8f 8g 8h 9 10 11 12 13 14 15 16 17 17a 17b 17c 18 19 20 21 22 23 (I) 23 (II) 24 24a 24b 24c 25 26 27 28 30 31 (I) 31 (II) 32 33 34 34a 34b 34c 34d 34e 34f 34g 34h 34i 34j 34k 35 36 37 38 39 40 41 42 43 43a 43b 44 (I) 44 (II) 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59a 59b 59c 59d 60 61 62 63 64 65 66 67 67c 68 69 70 71 72 73 74 75 76 76a 77 78 79 80 81 82 83 84 84a 84b 85 86 86a 87 89 89a 90 91 91a 91b 92 93 94 95 96 96a 97 98 99 100 101 102 103 104 105 106 106a 106b 106c 106d 106e 106f 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 125 126 127 128 129 130 131 132 133 134 135 136 (I) 136 (II) 136 (III) 136 (IV) 136 (V) 136 (VI) 136b 137 138 138a 138b 138c 138d 138e 139 140 141 142 142a 142b 142c 142d 143 144 145 146 147 147a 147b 147c 147d 147e 148 149 150 150a 151 151a 151b 151c 151d 152 153 154 154a 154b 155 156 157 158 159 160 161 162 162b 162c 163 (I) 163 (II) 164 165 166 167 167a 167b 168 169 170 171 172 173 174 175 (I) 175 (II) 176 177 178 179 180 181 (I) 181 (II) 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 (I) 255 (II) 255 (IV) 256 256a 256b 256c 256e 256f 256g 256h 256i 256j (I) 256j (II) 256k 256l 256m 256n 256o 256q 256r 256s 256t 256u 256v 256w 256x 256y 256aa 256ab 256ac 256ad 256ae 256af 256ag 256ah 256ai 256aj 256ak 256al 256am 256an 256ao 256ap 256aq 256ar 256as 257a 257b 257c 258 259 260 261 262 263 264 265 265a 266 267 267a 267b 267c 267d 268 269 270 270a 270b 270c 271 272 273 274 275 276 277 277a 277b 278 279 280 281 282 283 284 285 (I) 285 (II) 286 287 288 290 291 292 293 294 295 296 (I) 296 (II) 296 (III) 297 298 (I) 298 (II) 299 300 301 303 304 305 306 307 308 309 310 311 312 (I) 312 (II) 313 314 315 316 317 319 320 321 322 323 324 324a 324b 324c 324d 324e 324g 324h 324i 324j 324k 324l 325 326 327 328 329 330 331 332 333 334 335 336 337 338 338a 338b 338c 339 340 341 341a 342 342a 343 (I) 343 (II) 344 345 345a 345b 345c 345d 345e 346 347 348 349 350 351 352 353 354 355 355a 355b 356 356a 356b 356c 358 358a 358b 359 360 360a 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 375a 375b 375c 376 377 378 379 380 381 382 383 384 384a 384b 384d 384e 384f 385 386 386a 386b 386c 386d 386e 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 (I) 409 (II) 409 (III) 410 (I) 410 (II) 411 412 413 414 415 416 417 (I) 417 (II) 418 419 420 421 422 422a 422b (I) 422b (II) 422c 423 424 424a 425 426 427 428 429 (I) 429 (II) 430 431 432 433 434 435 435a 436 437 438 439 440 (I) 440 (II) 440 (III) 440 (IV) 441 442 443 (I) 443 (II) 444 445 446 447 448 (I) 448 (II) 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 (I) 502 (II) 503 504 505 506 507 508 509 510 511 513 514 515 (I) 515 (II) 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 (I) 583 (II) 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 (I) 600 (II) 601 602 603 (I) 603 (II) 604 605 (I) 605 (II) 606 607 608 (I) 608 (II) 609 610 611 612 613 (I) 613 (II) 614 (I) 614 (II) 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 (I) 696 (II) 696 (III) 696 (IV) 696 (V) 696 (VI) 697 698 699 700 701 702 (I) 702 (II) 703 704 705 706 707 708 (I) 708 (II) 708 (III) 709 710 710a 710b 710c 710d 710e (I) 710e (II) 710f 710g 710h 710i 710j 710k 710l 710m 710n 710o 710p 710q 710r 710t 710u 710v 710w 710x 710y 710z 710aa 710ab 710ac 710ad 710ae 710af 710ag 710ah 710ai 710aj 710ak 710al 710am 710an 710ao 710ap 710aq 710ar 710as 710at 710au 710av 710aw 710ax 710ay 710az 710ba 710bb 710bc 710bd 710be 710bf 710bg 710bh 710bi 710bj 710bk 710bl 710bm 710bn 710bo 710bp 710bq 710br 710bs 710bt 710bu 710bv 710bw 710bx 710by 710bz 710ca 710cb 710cc 710cd 710ce 710cf 710cg 710ch 710ci 711 712 713 714 715 716 716a 716b 717 718 719 720 720a 720b 721 722 (I) 722 (II) 723 724 725 (I) 725 (II) 725 (III) 725 (IV) 726 727 728 729 730 731 732 733 734 735 736 737 738 739 739a 739c 739d 739e 739f 739g 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 774a 774b 774c 774d 774e 774f 774g 774h 774i 774j 774k 774w 774x 774y 774z 774aa 774ab 774ac 774ad 774ae 774af 774ag 774ah 774ai 775 776 777 778 779 779a 780 780a 781 782 783 (I) 783 (II) 783a 783b 784 785 786 787 787a 787b 788 788a 788b 789 790 790a 790b 791 792 793 794 795 796 797 798 799 800 802 803 804 805 806 807 808 810 812 813 814 815 816 817 818 819 820 821 (I) 821 (II) 821 (III) 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 836a 836b 836c 836d 836e 836f 836h 836i 836j 836k 836l 836m 836q 836r 836s 836t 836u 836v 836w 836x 836y 836z 837 838 839 840 841 842 843 844 845 845a 845b 845c 845d 846 847 848 848a 848b 848c 849 850 850a 850b 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 875a 875b 875c 875d 875e 875f 875g 875h 875i 875j 875k 875l 876 877 878 879 880 881 882 883 (I) 883 (II) 883a 883b 883c 884 885 886 887 888 889 890 (I) 890 (II) 891 892 893 894 895 896 897 898 (I) 898 (II) 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 (I) 922 (II) 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 957a 957d 957e 957f 957h 957i (I) 957i (II) 958 959 960 961 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 977a 977b 977c 977d 977e 977f 977g 977h 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 (I) 998 (II) 998 (III) 999 999a 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1019a 1019b 1019c 1019d 1019e 1019f 1019g 1019h 1019i 1019j 1020 1021 1022 1022a 1023 1024 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1053 1054 1055 1056 1057 1058 1059 1060 1060a 1060b 1063 1063a 1064 1065 1066 1067 1068 1069 1070 1071 1072 1072a 1073 1074 1075 1076 1077 1078 1079 1080 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php