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
  • 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

Substitution

Processing...

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^.*(?= ) "; string substitution = @""; string input = @"Ticket A/5 21171 PC 17599 STON/O2. 3101282 113803 373450 330877 17463 349909 347742 237736 PP 9549 113783 A/5. 2151 347082 350406 248706 382652 244373 345763 2649 239865 248698 330923 113788 349909 347077 2631 19950 330959 349216 PC 17601 PC 17569 335677 C.A. 24579 PC 17604 113789 2677 A./5. 2152 345764 2651 7546 11668 349253 SC/Paris 2123 330958 S.C./A.4. 23567 370371 14311 2662 349237 3101295 A/4. 39886 PC 17572 2926 113509 19947 C.A. 31026 2697 C.A. 34651 CA 2144 2669 113572 36973 347088 PC 17605 2661 C.A. 29395 S.P. 3464 3101281 315151 C.A. 33111 CA 2144 S.O.C. 14879 2680 1601 348123 349208 374746 248738 364516 345767 345779 330932 113059 SO/C 14885 3101278 W./C. 6608 SOTON/OQ 392086 19950 343275 343276 347466 W.E.P. 5734 C.A. 2315 364500 374910 PC 17754 PC 17759 231919 244367 349245 349215 35281 7540 3101276 349207 343120 312991 349249 371110 110465 2665 324669 4136 2627 STON/O 2. 3101294 370369 11668 PC 17558 347082 S.O.C. 14879 A4. 54510 237736 27267 35281 2651 370372 C 17369 2668 347061 349241 SOTON/O.Q. 3101307 A/5. 3337 228414 C.A. 29178 SC/PARIS 2133 11752 113803 7534 PC 17593 2678 347081 STON/O2. 3101279 365222 231945 C.A. 33112 350043 W./C. 6608 230080 244310 S.O.P. 1166 113776 A.5. 11206 A/5. 851 Fa 265302 PC 17597 35851 SOTON/OQ 392090 315037 CA. 2343 371362 C.A. 33595 347068 315093 3101295 363291 113505 347088 PC 17318 1601 111240 382652 347742 STON/O 2. 3101280 17764 350404 4133 PC 17595 250653 LINE CA. 2343 SC/PARIS 2131 347077 230136 315153 113767 370365 111428 364849 349247 234604 28424 350046 230080 PC 17610 PC 17569 368703 4579 370370 248747 345770 CA. 2343 3101264 2628 A/5 3540 347054 3101278 2699 367231 112277 SOTON/O.Q. 3101311 F.C.C. 13528 A/5 21174 250646 367229 35273 STON/O2. 3101283 243847 11813 W/C 14208 SOTON/OQ 392089 220367 21440 349234 19943 PP 4348 SW/PP 751 A/5 21173 236171 4133 36973 347067 237442 347077 C.A. 29566 W./C. 6609 26707 C.A. 31921 28665 SCO/W 1585 2665 367230 W./C. 14263 STON/O 2. 3101275 2694 19928 347071 250649 11751 244252 362316 347054 113514 A/5. 3336 370129 2650 PC 17585 110152 PC 17755 230433 384461 347077 110413 112059 382649 C.A. 17248 3101295 347083 PC 17582 PC 17760 113798 LINE 250644 PC 17596 370375 13502 347073 239853 382652 C.A. 2673 336439 347464 345778 A/5. 10482 113056 349239 345774 349206 237798 370373 19877 11967 SC/Paris 2163 349236 349233 PC 17612 2693 113781 19988 PC 17558 9234 367226 LINE 226593 A/5 2466 113781 17421 PC 17758 P/PP 3381 PC 17485 11767 PC 17608 250651 349243 F.C.C. 13529 347470 244367 29011 36928 16966 A/5 21172 349219 234818 248738 CA. 2343 PC 17760 345364 28551 363291 111361 367226 113043 PC 17582 345764 PC 17611 349225 113776 16966 7598 113784 230080 19950 248740 244361 229236 248733 31418 386525 C.A. 37671 315088 7267 113510 2695 349237 2647 345783 113505 237671 330931 330980 347088 SC/PARIS 2167 2691 SOTON/O.Q. 3101310 370365 C 7076 110813 2626 14313 PC 17477 11765 3101267 323951 PC 17760 349909 PC 17604 C 7077 113503 2648 347069 PC 17757 2653 STON/O 2. 3101293 113789 349227 S.O.C. 14879 CA 2144 27849 367655 SC 1748 113760 350034 3101277 35273 PP 9549 350052 350407 28403 244278 240929 STON/O 2. 3101289 341826 4137 STON/O2. 3101279 315096 28664 347064 29106 312992 4133 349222 394140 19928 239853 STON/O 2. 3101269 343095 28220 250652 28228 345773 349254 A/5. 13032 315082 347080 370129 A/4. 34244 2003 250655 364851 SOTON/O.Q. 392078 110564 376564 SC/AH 3085 STON/O 2. 3101274 13507 113760 W./C. 6608 29106 19950 C.A. 18723 F.C.C. 13529 345769 347076 230434 65306 33638 250644 113794 2666 113786 C.A. 34651 65303 113051 17453 A/5 2817 349240 13509 17464 F.C.C. 13531 371060 19952 364506 111320 234360 A/S 2816 SOTON/O.Q. 3101306 239853 113792 36209 2666 323592 315089 C.A. 34651 SC/AH Basle 541 7553 110465 31027 3460 350060 3101298 CA 2144 239854 A/5 3594 4134 11967 4133 19943 11771 A.5. 18509 C.A. 37671 65304 SOTON/OQ 3101317 113787 PC 17609 A/4 45380 2627 36947 C.A. 6212 113781 350035 315086 364846 330909 4135 110152 PC 17758 26360 111427 C 4001 1601 382651 SOTON/OQ 3101316 PC 17473 PC 17603 349209 36967 C.A. 34260 371110 226875 349242 12749 349252 2624 111361 2700 367232 W./C. 14258 PC 17483 3101296 29104 26360 2641 2690 2668 315084 F.C.C. 13529 113050 PC 17761 364498 13568 WE/P 5735 347082 347082 2908 PC 17761 693 2908 SC/PARIS 2146 363291 C.A. 33112 17421 244358 330979 2620 347085 113807 11755 PC 17757 110413 345572 372622 349251 218629 SOTON/OQ 392082 SOTON/O.Q. 392087 A/4 48871 349205 349909 2686 350417 S.W./PP 752 11769 PC 17474 14312 A/4. 20589 358585 243880 13507 2689 STON/O 2. 3101286 237789 17421 28403 13049 3411 110413 237565 13567 14973 A./5. 3235 STON/O 2. 3101273 36947 A/5 3902 364848 SC/AH 29037 345773 248727 LINE 2664 PC 17485 243847 349214 113796 364511 111426 349910 349246 113804 SC/Paris 2123 PC 17582 347082 SOTON/O.Q. 3101305 367230 370377 364512 220845 347080 A/5. 3336 230136 31028 2659 11753 2653 350029 54636 36963 219533 13502 349224 334912 27042 347743 13214 112052 347088 237668 STON/O 2. 3101292 C.A. 31921 3101295 376564 350050 PC 17477 347088 1601 2666 PC 17572 349231 13213 S.O./P.P. 751 CA. 2314 349221 231919 8475 330919 365226 S.O.C. 14879 349223 364849 29751 35273 PC 17611 2623 5727 349210 STON/O 2. 3101285 S.O.C. 14879 234686 312993 A/5 3536 19996 29750 F.C. 12750 C.A. 24580 244270 239856 349912 342826 4138 CA 2144 PC 17755 330935 PC 17572 6563 CA 2144 29750 SC/Paris 2123 3101295 349228 350036 24160 17474 349256 1601 2672 113800 248731 363592 35852 17421 348121 PC 17757 PC 17475 2691 36864 350025 250655 223596 PC 17476 113781 2661 PC 17482 113028 19996 7545 250647 348124 PC 17757 34218 36568 347062 248727 350048 12233 250643 113806 315094 31027 36866 236853 STON/O2. 3101271 24160 2699 239855 28425 233639 54636 W./C. 6608 PC 17755 349201 349218 16988 19877 PC 17608 376566 STON/O 2. 3101288 WE/P 5735 C.A. 2673 250648 113773 335097 29103 392096 345780 349204 220845 250649 350042 29108 363294 110152 358585 SOTON/O2 3101272 2663 113760 347074 13502 112379 364850 371110 8471 345781 350047 S.O./P.P. 3 2674 29105 347078 383121 364516 36865 24160 2687 17474 113501 W./C. 6607 SOTON/O.Q. 3101312 374887 3101265 382652 C.A. 2315 PC 17593 12460 239865 CA. 2343 PC 17600 349203 28213 17465 349244 2685 345773 250647 C.A. 31921 113760 2625 347089 347063 112050 347087 248723 113806 3474 A/4 48871 28206 347082 364499 112058 STON/O2. 3101290 S.C./PARIS 2079 C 7075 347088 12749 315098 19972 392096 3101295 368323 1601 S.C./PARIS 2079 367228 113572 2659 29106 2671 347468 2223 PC 17756 315097 392092 1601 11774 SOTON/O2 3101287 S.O./P.P. 3 113798 2683 315090 C.A. 5547 CA. 2343 349213 248727 17453 347082 347060 2678 PC 17592 244252 392091 36928 113055 2666 2629 350026 28134 17466 CA. 2343 233866 236852 SC/PARIS 2149 PC 17590 345777 347742 349248 11751 695 345765 P/PP 3381 2667 7534 349212 349217 11767 230433 349257 7552 C.A./SOTON 34068 SOTON/OQ 392076 382652 211536 112053 W./C. 6607 111369 370376 "; 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