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

/
/
gmi

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]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$"; final String string = "S43 1QQ\n" + "HP22 4EL\n" + "SN13 8NF\n" + "LA14 1JH\n" + "WV14 8GW\n" + "LS17 8XU\n" + "CH1 3AX\n" + "L31 8AR\n" + "RG14 6SY\n" + "AL7 1AU\n" + "M27 0NG\n" + "SA13 3UU\n" + "OL16 4TG\n" + "B43 5PY\n" + "PR4 3FN\n" + "GY6 8NQ\n" + "CF83 1TJ\n" + "IV31 6DB\n" + "WC1H 0AA\n" + "LS17 7LG\n" + "S25 2NT\n" + "PO22 9LH\n" + "NR23 1BP\n" + "SL2 3HR\n" + "PO7 5TP\n" + "PE8 5LL\n" + "DA1 4TT\n" + "TA2 8AQ\n" + "TS24 0HS\n" + "WV6 0PZ\n" + "PE7 3TX\n" + "BS24 7NF\n" + "NR12 8PL\n" + "BN13 2TG\n" + "LL13 7JF\n" + "SO51 7AE\n" + "BT48 6UE\n" + "SM6 8BF\n" + "WA8 9PH\n" + "HR1 4JR\n" + "TN1 1YJ\n" + "WS2 9JT\n" + "SL1 1PG\n" + "RH4 2WS\n" + "DY5 3TG\n" + "CM22 6XT\n" + "LN5 8HX\n" + "OX14 1PJ\n" + "BL0 0LR\n" + "TW17 9NL\n" + "G60 5NH\n" + "SY23 3RH\n" + "NG18 5JZ\n" + "CF44 7ES\n" + "YO17 8RT\n" + "WA13 9HZ\n" + "LL47 6TF\n" + "BT45 7HA\n" + "HP18 0PH\n" + "BD19 4BU\n" + "CO7 8AE\n" + "WN2 3NF\n" + "EH3 9SU\n" + "HU5 4AY\n" + "G76 8ND\n" + "BN7 2FH\n" + "TN3 0BE\n" + "BN26 5SJ\n" + "BA3 2PG\n" + "DH1 2TD\n" + "BH14 0LT\n" + "BL3 1QB\n" + "TN4 9XX\n" + "LL30 2YQ\n" + "SE6 9SG\n" + "B61 0LU\n" + "TA20 2SZ\n" + "NP4 5SA\n" + "YO30 4UN\n" + "YO30 2AY\n" + "NN13 5JX\n" + "PO17 5BE\n" + "BS31 2QG\n" + "GU7 9GR\n" + "CV37 9XY\n" + "DH2 2DA\n" + "BH9 3AW\n" + "PE28 2GE\n" + "IV30 8LS\n" + "CV13 0LF\n" + "PO9 2RB\n" + "NR2 3HS\n" + "TS18 2XB\n" + "LL18 4LU\n" + "LA9 4SX\n" + "PL9 9RA\n" + "HR4 7PL\n" + "L12 0NL\n" + "DN9 2NH\n" + "IV36 2TF\n" + "ML4 3NW\n" + "PE34 3FH\n" + "W1U 6RB\n" + "BS21 7XG\n" + "M8 4QU\n" + "DD2 5RH\n" + "BT78 3AJ\n" + "TN16 1EN\n" + "RM6 5LU\n" + "GY7 9RL\n" + "CW11 1AL\n" + "GL54 5RG\n" + "S5 7LB\n" + "ST5 5AT\n" + "SK11 8AU\n" + "CB7 4PJ\n" + "GL2 9RF\n" + "SK15 3NX\n" + "NN3 9BW\n" + "IP25 7BG\n" + "LN13 0NN\n" + "KY12 9DT\n" + "ML2 0NA\n" + "SK12 2LD\n" + "CT21 6AW\n" + "CV37 7ND\n" + "KY11 1QB\n" + "YO32 5TY\n" + "SP6 3HH\n" + "BN9 9NA\n" + "DE56 0SJ\n" + "YO62 7LE\n" + "PE6 7QN\n" + "CA28 9DX\n" + "SN3 4NA\n" + "WF1 9SE\n" + "M46 9BG\n" + "ML1 5RN\n" + "NE8 4UD\n" + "CA13 9EG\n" + "CA1 1DH\n" + "SA10 8LT\n" + "E14 9WR\n" + "TF2 7ES\n" + "SS17 8PH\n" + "GL50 2DX\n" + "SE3 3DE\n" + "SM1 4SQ\n" + "B15 3LL\n" + "GL5 2NG\n" + "CR0 8EP\n" + "S64 8DE\n" + "PO1 4BE\n" + "EH9 1QN\n" + "S21 5RS\n" + "LL29 8YU\n" + "W14 8AP\n" + "RG6 1BT\n" + "SG8 9FG\n" + "KT15 1DJ\n" + "NN9 5XW\n" + "SY8 1AJ\n" + "TF7 9ST\n" + "ME14 2RZ\n" + "DE11 7AT\n" + "DN21 4BB\n" + "HU16 5LU\n" + "BD3 0RG\n" + "LE5 6HN\n" + "LE15 6RZ\n" + "NN14 1FD\n" + "PE2 5PY\n" + "PA4 9RF\n" + "KY10 2PY\n" + "NG5 5TJ\n" + "SA43 2JD\n" + "NE16 6LU\n" + "W4 5DL\n" + "OX29 6TN\n" + "DA1 1JN\n" + "S72 9HB\n" + "TR1 1SX\n" + "LE17 5NL\n" + "CM16 6BH\n" + "B2 4WJ\n" + "HA4 8BP\n" + "M18 7QX\n" + "DN4 0HA\n" + "TF2 6SG\n" + "NE3 4AD\n" + "SW2 5TN\n" + "TF10 9EE\n" + "PO22 9DY\n" + "CF32 9LF\n" + "TA6 3UD\n" + "BS9 1BH\n" + "NG34 9WH\n" + "CH64 0SP\n" + "NN3 2SQ\n" + "HD3 3HX\n" + "S9 4NT\n" + "BT23 4NP\n" + "SG5 3UA\n" + "S72 0DE\n" + "DD2 1TH\n" + "AL2 3SQ\n" + "EH26 0AR\n" + "BB1 1DU\n" + "NE29 7PG\n" + "SP8 5NF\n" + "NG14 7FU\n" + "G72 7SP\n" + "SK17 6UD\n" + "BN43 6LZ\n" + "RH12 1JZ\n" + "TN28 8XF\n" + "WF17 6AR\n" + "PR2 1AG\n" + "BT6 8EY\n" + "ST5 1EJ\n" + "BT13 1JA\n" + "S80 4FL\n" + "S10 2BA\n" + "WS13 8NZ\n" + "CV4 9DJ\n" + "RG1 8AN\n" + "NR20 5TT\n" + "CA24 3HX\n" + "WS7 2EL\n" + "SE8 5BA\n" + "OX12 9YX\n" + "SM3 8AG\n" + "LL18 2US\n" + "FY2 0EQ\n" + "HD5 8DF\n" + "PE1 3SY\n" + "EX3 0AP\n" + "NW5 4JS\n" + "CF34 0JA\n" + "NE61 5AH\n" + "LS13 4RS\n" + "B45 9TH\n" + "S8 9QX\n" + "NG19 0PD\n" + "HA5 5BP\n" + "NE47 9NR\n" + "PO8 8BN\n" + "LE8 9FL\n" + "UB1 2XQ\n" + "CF45 4LJ\n" + "TS12 2HY\n" + "ST5 1EH\n" + "GU35 0GQ\n" + "KY8 5PQ\n" + "BR5 2PH\n" + "MK4 4JG\n" + "LD3 0YQ\n" + "LU2 9UE\n" + "BS22 8SZ\n" + "KT15 1RH\n" + "PA2 6EQ\n" + "NE46 3QJ\n" + "CB9 8EL\n" + "SW17 9RS\n" + "PO21 5NJ\n" + "NG6 0LR\n" + "SP3 5EL\n" + "NR33 9AN\n" + "PE28 5PJ\n" + "CO9 4BD\n" + "LE3 0RA\n" + "KT10 0TX\n" + "IP3 8RG\n" + "NP7 9BE\n" + "BL4 9BT\n" + "JE3 5HD\n" + "CV11 6EJ\n" + "CM1 1NG\n" + "PE13 1RL\n" + "OL6 9NJ\n" + "DE1 2XX\n" + "SG8 6EL\n" + "WV6 9PY\n" + "DN33 1RQ\n" + "OX26 6QH\n" + "AB39 2TP\n" + "PO18 0RL\n" + "DE75 7XD\n" + "CO11 1AG\n" + "SS9 2SF\n" + "DH3 4SN\n" + "TS27 3AR\n" + "SG15 6RB\n" + "S61 4QH\n" + "PL14 4EP\n" + "N14 4AU\n" + "SA20 0UU\n" + "DG1 4BZ\n" + "EH12 6EU\n" + "SS0 9JQ\n" + "PE13 5RB\n" + "E9 5BQ\n" + "NE63 9JD\n" + "LE3 2XR\n" + "GU17 9DW\n" + "TS3 9EN\n" + "IP9 2BB\n" + "RG31 6FZ\n" + "PL20 6QW\n" + "SK13 7DP\n" + "BS37 6QN\n" + "LA9 7HJ\n" + "LU1 1NE\n" + "LL68 0RD\n" + "M28 7FQ\n" + "UB8 3RY\n" + "PO4 0DN\n" + "HA7 4UY\n" + "LE2 6BA\n" + "CF64 2JS\n" + "SE21 7AN\n" + "LE9 7DU\n" + "HX1 5PU\n" + "ST6 3AH\n" + "SA43 1AB\n" + "IV36 2LP\n" + "NE31 1AN\n" + "CA6 4NW\n" + "G73 3PD\n" + "WR2 4RE\n" + "TS14 6JG\n" + "RH12 9EX\n" + "CF62 6NZ\n" + "WF17 9PD\n" + "HA3 5NT\n" + "TN15 6DZ\n" + "ME20 6AP\n" + "RM15 5RL\n" + "SN25 2GS\n" + "PE28 4DS\n" + "FY5 2ED\n" + "CH66 2JQ\n" + "EH20 9BG\n" + "EX16 8DX\n" + "NR21 7PU\n" + "FY3 9NZ\n" + "E9 7RR\n" + "M20 2PY\n" + "KY11 1NR\n" + "SW17 9JA\n" + "WA15 6ES\n" + "GU10 1JZ\n" + "WR6 5SA\n" + "TR1 3DQ\n" + "SY18 6AP\n" + "WD3 1LB\n" + "NE25 0FR\n" + "BA2 2HL\n" + "N20 9PH\n" + "EH32 0AZ\n" + "L69 3ZX\n" + "KY1 4AH\n" + "PE26 2SJ\n" + "SA19 9NY\n" + "CH45 2LD\n" + "EX33 1NH\n" + "BB18 5AQ\n" + "DY9 0AB\n" + "NG31 9AP\n" + "KY11 4AQ\n" + "LU3 2HB\n" + "BT38 8XD\n" + "SN7 7JX\n" + "NG8 5AG\n" + "TA6 6DL\n" + "SG1 1JD\n" + "WA1 4JN\n" + "SN12 8NL\n" + "PO4 0ND\n" + "ME19 4FL\n" + "HP20 1YP\n" + "WS1 4LH\n" + "DG16 5JQ\n" + "WV4 4LF\n" + "HR9 7SJ\n" + "BS9 1SZ\n" + "WA14 5NZ\n" + "SG11 1AL\n" + "SK15 3EQ\n" + "BD2 4LZ\n" + "ME6 5JS\n" + "SE26 6XD\n" + "BH17 8PT\n" + "UB2 5QG\n" + "CV31 1HD\n" + "BT53 6HF\n" + "GL51 3WE\n" + "GL17 0GX\n" + "KT15 1BZ\n" + "CF32 0DB\n" + "DA1 5LT\n" + "AL2 2SH\n" + "DA12 2LT\n" + "BA6 8NR\n" + "SK23 7GB\n" + "SA61 2JG\n" + "GU4 7UP\n" + "EX2 9UP\n" + "CF23 9JB\n" + "PE1 3JL\n" + "BT26 6PS\n" + "EX2 4NX\n" + "BT78 5NH\n" + "NE28 6HQ\n" + "CB3 9DA\n" + "NW9 7PA\n" + "HD7 4QJ\n" + "EX22 6NQ\n" + "GU6 8JN\n" + "B17 8AT\n" + "ST3 5QW\n" + "NN3 9UY\n" + "M32 9AN\n" + "EX20 2SG\n" + "WR5 2RB\n" + "CM21 9AJ\n" + "RG10 9JP\n" + "GU33 7HJ\n" + "FK7 8BW\n" + "ST2 9BB\n" + "HP13 5BH\n" + "JE4 0TD\n" + "CR0 0LL\n" + "NG12 5GT\n" + "NW8 0AU\n" + "FY7 7BG\n" + "AB11 6HS\n" + "TN2 9SW\n" + "NR4 6BX\n" + "PL23 1DL\n" + "OX2 7BD\n" + "CF35 5EU\n" + "FY3 7QN\n" + "PA15 4QF\n" + "SO15 2PQ\n" + "PO19 1EH\n" + "CB24 5HY\n" + "W13 8DU\n" + "WF5 9NL\n" + "EH22 4HB\n" + "M12 5BW\n" + "S65 2RB\n" + "BT60 2QX\n" + "KA13 6WG\n" + "KA27 8LE\n" + "TN27 9LB\n" + "BS22 7AF\n" + "GU30 7QF\n" + "CM3 8DF\n" + "WD23 1LH\n" + "NN13 5LJ\n" + "DA12 2PU\n" + "WV12 5SJ\n" + "TS10 9BB\n" + "LA4 6NY\n" + "SY13 1RB\n" + "TA3 7HQ\n" + "GU51 1GR\n" + "PL28 8RX\n" + "WA13 9SU\n" + "B64 5LP\n" + "DN16 3WR\n" + "CM1 4NL\n" + "TW13 4QD\n" + "CA7 3BB\n" + "BT51 4HA\n" + "SM6 8AE\n" + "OL13 8PE\n" + "HA7 2EG\n" + "HU5 1NA\n" + "W9 1HE\n" + "FK1 5LA\n" + "NR34 9DL\n" + "KT14 6RQ\n" + "DN22 8DU\n" + "NE24 5RR\n" + "SP11 9AU\n" + "BA14 7SY\n" + "DH1 2BP\n" + "IV2 7AJ\n" + "GU34 5ND\n" + "CV2 2JR\n" + "E11 1BP\n" + "BT35 6PW\n" + "EX33 2HL\n" + "DN32 0AJ\n" + "SE6 4RY\n" + "LL53 7EE\n" + "NR25 6RJ\n" + "BT92 8JP\n" + "NW2 1WR\n" + "CA11 8FD\n" + "B26 1AR\n" + "EX36 4EN\n" + "B60 2AL\n" + "SR7 0AA\n" + "NR32 3EQ\n" + "HA8 6TD\n" + "SS8 1AN\n" + "RM3 0ND\n" + "TW8 8QQ\n" + "GL51 9RU\n" + "SR1 1TZ\n" + "MK18 5JY\n" + "CO4 5JF\n" + "BT34 5DU\n" + "PE34 4RG\n" + "HA8 6DE\n" + "CM9 4LE\n" + "BH8 8DH\n" + "GU2 8ES\n" + "PE28 0BD\n" + "SO45 4NB\n" + "RG12 7JL\n" + "NE65 7DP\n" + "BT41 1DA\n" + "CF33 6GA\n" + "NG14 6EF\n" + "SN11 8AE\n" + "SW6 1HR\n" + "DL11 6AD\n" + "KA18 1NA\n" + "L14 6TS\n" + "NG2 2GQ\n" + "BT33 0TU\n" + "BL6 7LZ\n" + "AB16 7QT\n" + "DN21 4NT\n" + "GL4 4XR\n" + "PL12 4AY\n" + "LS11 8PD\n" + "TF9 2BU\n" + "SL2 4FD\n" + "RH20 2BG\n" + "ST4 4SX\n" + "PE12 6RL\n" + "M22 9RW\n" + "CT10 3NF\n" + "NE30 3RX\n" + "TW20 9JL\n" + "AB24 4LP\n" + "B16 8HG\n" + "BT4 3HT\n" + "SA4 3XX\n" + "NW1 7NZ\n" + "G69 7JA\n" + "G78 4DA\n" + "M12 4AH\n" + "BA8 0SJ\n" + "BH1 9WL\n" + "G69 8EU\n" + "OX44 9JN\n" + "DY5 3JU\n" + "PA7 5QH\n" + "NN18 0TL\n" + "TR14 0PZ\n" + "NR33 8FW\n" + "AB16 5UY\n" + "KT13 0BU\n" + "NW1W 7GQ\n" + "FK1 3DF\n" + "GY3 5HA\n" + "OL8 4QL\n" + "NG18 1JR\n" + "BN6 0ER\n" + "NE28 6HL\n" + "N1 9FQ\n" + "FK7 7LB\n" + "DG1 3JX\n" + "LU2 7RE\n" + "OX10 9EN\n" + "NR33 0TQ\n" + "IP24 1LB\n" + "EX6 8RE\n" + "LS28 5FU\n" + "AL10 0FF\n" + "CM13 1HS\n" + "CV3 5JD\n" + "RM3 7BT\n" + "M30 7WE\n" + "GU17 0AS\n" + "HA6 2LU\n" + "NR2 4PP\n" + "DY9 7EG\n" + "HA9 9RA\n" + "CF5 6EW\n" + "DT9 6DF\n" + "KT3 5QJ\n" + "TW18 2LH\n" + "SP1 2BW\n" + "ME17 4BS\n" + "W14 4DR\n" + "SA33 4JU\n" + "ST5 0EY\n" + "MK42 9JA\n" + "WF17 0EB\n" + "BN1 3TX\n" + "W11 1NR\n" + "G74 4NJ\n" + "GU14 8UL\n" + "OX1 5JG\n" + "SO14 0DF\n" + "JE2 4UP\n" + "HP9 2UW\n" + "SL60 1HU\n" + "AB56 4PQ\n" + "UB6 8QS\n" + "EN3 6PX\n" + "WS9 8HQ\n" + "IP2 0NX\n" + "ST18 0AZ\n" + "PR2 1JL\n" + "NW1 9LJ\n" + "BD6 1AE\n" + "NE34 8NJ\n" + "SO50 6AB\n" + "WF4 1ED\n" + "OL3 5US\n" + "WA14 1BP\n" + "BT17 9NH\n" + "CO2 9AT\n" + "SE20 7PU\n" + "RH16 2BZ\n" + "BT13 3RS\n" + "NW1 1AT\n" + "ST1 5UB\n" + "NG5 9HW\n" + "GL50 1QF\n" + "TQ7 1JN\n" + "PL17 7DQ\n" + "DE72 3DX\n" + "BT15 4FJ\n" + "B8 3QW\n" + "BS23 3TW\n" + "B76 1QJ\n" + "WS3 3UE\n" + "LS22 4AQ\n" + "G46 6LS\n" + "RG14 2DY\n" + "FY2 0AX\n" + "NE5 1BL\n" + "CA4 9TN\n" + "NG34 7QE\n" + "S18 8ZT\n" + "IP8 3RT\n" + "NG18 5EP\n" + "PE27 4SQ\n" + "LL55 4AD\n" + "WC1N 3LR\n" + "DE6 1AZ\n" + "S13 8RE\n" + "NE43 7BW\n" + "SS13 1BD\n" + "EH14 7BX\n" + "EC2A 3NF\n" + "TQ14 9HP\n" + "CV1 5FG\n" + "CH1 5EA\n" + "PH2 0BN\n" + "ML11 8LL\n" + "NR22 6AT\n" + "LA9 7QA\n" + "GL11 5SP\n" + "M26 2UT\n" + "NE31 2UL\n" + "NW8 7AF\n" + "B77 3BU\n" + "HP1 2BU\n" + "SY1 1QU\n" + "IP11 2PR\n" + "LL55 1TW\n" + "WN4 8SG\n" + "ST6 1HE\n" + "PE8 6YJ\n" + "SW6 5TH\n" + "SK6 1LD\n" + "SA5 8ER\n" + "BH15 1HP\n" + "W8 4BD\n" + "B23 7BH\n" + "IP12 2SS\n" + "IP6 0AS\n" + "BT36 6AB\n" + "SG8 9BL\n" + "BH12 1DB\n" + "OX16 6NX\n" + "IG9 6BU\n" + "DL11 7EE\n" + "SS9 3AN\n" + "CM15 0NH\n" + "NP22 4PU\n" + "CO15 4LS\n" + "CF23 6AU\n" + "GL13 9NL\n" + "CM2 7ES\n" + "MK42 9YP\n" + "KY7 6PN\n" + "NR13 3NS\n" + "DN21 3HD\n" + "EX6 7TD\n" + "TR4 8NY\n" + "NW1 0ET\n" + "DN37 0XB\n" + "SY5 6SG\n" + "NE23 7SY\n" + "HP2 5LD\n" + "NG3 6AE\n" + "SE16 7HD\n" + "CF32 7DD\n" + "OL8 4EL\n" + "CV11 4AY\n" + "DH6 3JN\n" + "NE36 0EL\n" + "S6 4LZ\n" + "GU11 1NF\n" + "PO14 1JL\n" + "GL16 7AE\n" + "TN19 7WS\n" + "EN1 2PD\n" + "NP4 5HR\n" + "IV36 1ZZ\n" + "NE46 4LA\n" + "KA30 8DA\n" + "HP9 2GN\n" + "CF11 9DD\n" + "B12 9RP\n" + "HG3 2JZ\n" + "IG5 0BG\n" + "G71 6QB\n" + "CO10 2AP\n" + "OX29 9UA\n" + "PR3 3SG\n" + "PA1 3SG\n" + "CB8 8TH\n" + "IP28 8NQ\n" + "LS12 1DB\n" + "WR2 4BW\n" + "PR1 0BQ\n" + "AB51 5EE\n" + "DH8 8JH\n" + "RH12 3TY\n" + "S41 0GE\n" + "LL53 8TF\n" + "BT19 1AA\n" + "LE1 9TG\n" + "LN6 0AE\n" + "CB4 2BE\n" + "WV10 6QT\n" + "DE22 2GP\n" + "G68 0AB\n" + "YO32 9PX\n" + "BS35 2ER\n" + "DE65 6DT\n" + "TW1 4QS\n" + "LL14 3TG\n" + "HU17 0DN\n" + "IP21 4DJ\n" + "HR6 0AX\n" + "BL3 4BY\n" + "HU11 4QN\n" + "BN27 2RJ\n" + "G32 0TG\n" + "GU25 4HJ\n" + "SS11 7EU\n" + "LE3 0FN\n" + "HX4 9PL\n" + "BT35 5DQ\n" + "SW16 1QJ\n" + "NW6 6TG\n" + "S40 2AX\n" + "WS11 1RG\n" + "ME15 7RR\n" + "SO18 1FY\n" + "WR4 9YY\n" + "WF11 0DS\n" + "HG3 1SQ\n" + "TA9 4LT\n" + "CH61 9NG\n" + "HG3 3TH\n" + "LE14 3BY\n" + "CV10 0AA\n" + "NW10 3LE\n" + "N9 9AA\n" + "G64 1SH\n" + "WA3 3NJ\n" + "CV2 2RW\n" + "AB54 4LP\n" + "WR11 2GG\n" + "LS21 1RZ\n" + "B17 0TJ\n" + "WF8 1NA\n" + "OL16 5NE\n" + "CA6 5PJ\n" + "BT8 6GY\n" + "TA5 1YU\n" + "RH13 5LN\n" + "PE19 5UG\n" + "SW7 5DT\n" + "PE19 1JN\n" + "YO23 7DZ\n" + "NW11 8EG\n" + "RH6 9GG\n" + "EH54 7DA\n" + "SO45 1BE\n" + "CM14 4ET\n" + "BT81 7AN\n" + "LL21 0RW\n" + "RH8 0HT\n" + "PL11 2RA\n" + "SE18 6GG\n" + "L3 4AE\n" + "EN8 0BG\n" + "IG3 9JH\n" + "BT47 6XL\n" + "NR2 1LZ\n" + "DN32 7PR\n" + "N8 8LP\n" + "YO25 8JT\n" + "PE4 5DR\n" + "NG16 4FJ\n" + "SW17 8PY\n" + "DN37 9RE\n" + "M45 6DX\n" + "G31 5BS\n" + "PL5 3ES\n" + "HA5 5RJ\n" + "SO24 0NU\n" + "DN31 3PU\n" + "IP28 7NF\n" + "WF12 8PQ\n" + "LL14 6LH\n" + "S8 9GA\n" + "ME7 4EJ\n" + "YO1 7EH\n" + "DN9 2AX\n" + "LE18 2BB\n" + "RG30 4JG\n" + "M45 8NH\n" + "NR33 8AF\n" + "SE8 3NT\n" + "ME17 3JY\n" + "DT11 9PW\n" + "CF23 9DP\n" + "WS13 7BD\n" + "RG31 6QU\n" + "SR3 2XD\n" + "TA18 8NH\n" + "NW11 7SB\n" + "BD17 5HX\n" + "TS1 5TS\n" + "NW1 4NR\n" + "YO42 2NH\n" + "BD10 8LQ\n" + "G61 3SS\n" + "WD23 4HQ\n" + "WD3 1XR\n" + "M27 5ET\n" + "JE4 8ZZ\n" + "SL2 3AY\n" + "RH17 6SA\n" + "NR3 2NL\n" + "G33 6LZ\n" + "HG1 5JS\n" + "HU9 5PQ\n" + "CT11 0HZ\n" + "AL1 5SY\n" + "BT13 3PU\n" + "CF39 9LR\n" + "KY2 6PU\n" + "S61 2UF\n" + "PA16 7BW\n" + "DY12 2JQ\n" + "SK13 6NA\n" + "OX12 9ZE\n" + "B44 9ST\n" + "NE47 7EA\n" + "PE10 0HE\n" + "SM6 9ER\n" + "ME10 3ST\n" + "DY10 4QQ\n" + "CV37 0UN\n" + "PE32 1QJ\n" + "CM7 9LP\n" + "AL4 9UJ\n" + "M33 2NA\n" + "TN15 0HR\n" + "LS12 1HZ\n" + "KT2 5PA\n" + "SA4 8PH\n" + "LS25 2EQ\n" + "DE24 0PS\n" + "OL12 8DR\n" + "BT14 8HU\n" + "KA19 7AJ\n" + "NP7 8RR\n" + "SE3 0UX\n" + "RG26 3EA\n" + "NR30 5RE\n" + "KT18 5BU\n" + "CF5 5JG\n" + "BA22 7ES\n" + "UB5 5LY\n" + "SN1 4JQ\n" + "WA5 4LA\n" + "DN20 0HE\n" + "SS7 1SS\n" + "L13 3DE\n" + "KT1 3QZ\n" + "G33 1SS\n" + "DN14 9PW\n" + "N1 2SB\n" + "SS1 3NJ\n" + "CF23 9LX\n" + "EX14 1PZ\n" + "CF48 1NN\n" + "EX20 1RX\n" + "B27 7QA\n" + "SO41 0WR\n" + "CO7 6UP\n" + "EH54 6RX\n" + "SW18 1RX\n" + "SN9 5AX\n" + "RG4 9RS\n" + "KT9 1SE\n" + "CM7 3YN\n" + "BB4 9SA\n" + "CR8 5DH\n" + "EN2 6HE\n" + "RH19 2PG\n" + "NG34 7TL\n" + "CV21 1JH\n" + "TQ3 1QX\n" + "ST14 8RP\n" + "DA7 4PE\n" + "TN29 9DU\n" + "HU16 4BT\n" + "N8 0LY\n" + "SK6 1AW\n" + "IP15 5JW\n" + "SN2 2FR\n" + "SE16 2PQ\n" + "ST13 6LE\n" + "SA1 8DT\n" + "LS5 3DN\n" + "B65 8DN\n" + "TF6 5DP\n" + "B66 3LE\n" + "L39 3RD\n" + "RM10 9YU\n" + "NN6 9JY\n" + "CF14 5WF\n" + "LS6 3HD\n" + "PL2 3NW\n" + "PR4 6RL\n" + "DL8 4AN\n" + "EH4 2RQ\n" + "SL1 7HT\n" + "LL22 8DH\n" + "N21 1BL\n" + "BA12 0RB\n" + "TD5 7LN\n" + "DL14 9AU\n" + "RG9 5QX\n" + "SA32 8PF\n" + "SO30 2LP\n" + "HP23 6EH\n" + "PL25 5JQ\n" + "G75 8WA\n" + "TS6 7EW\n" + "BT14 6BZ\n" + "WS15 1BA\n" + "WF1 9RT\n" + "DN15 6DW\n" + "SG6 1UG\n" + "AB53 5PJ\n" + "DN33 2PF\n" + "IP3 0NT\n" + "NP20 3FX\n" + "N15 4LJ\n" + "WA15 7QB\n" + "HU6 7EG\n" + "CV21 1SQ\n" + "TR26 2PY\n" + "LA14 1SR\n" + "OX7 3HR\n" + "W10 4UF\n" + "S12 2QZ\n" + "BA22 9TB\n" + "CB23 7GD"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | 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