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"
"
gmx

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r""" ^ (\d{1,3})\s+ (?:(?![\d,.]+\n).)+ ([\d.,]+)\n """ test_str = ("Adjustment of Profits Computation\n\n" " Turnover from Trade or Profession 108,036\n\n" " Profit Per Accounts 35,226\n\n" "Addback: Disallowable Expenditure\n\n" " Depreciation 325\n\n" " Entertaining 29\n\n" " - 354\n\n" "Deduct: Allowances and Other Deductions\n\n" " Capital Allowances 1,337\n\n" " 34,243 (1,337)\n\n" " Adjusted Case I Profit 34,243\n\n" "Losses Memorandum 1 Trade Property\n\n" " Losses Brought Forward 16,758 -\n\n" " Used in this Computation Against Trading Profits (16,758) - (16,758)\n\n" " Used in this Computation Against General Profits -\n\n" " Net Trading and Professional Profit 17,485\n\n" "Losses Memorandum 2 Trade Property\n\n" "Losses Carried Back from Later Period to be Used Against -\n\n" " General Profits\n\n" " Used in this Computation Against General Profits -\n\n" " Losses from Current Period - -\n\n" " Loss Surrendered for R & D Credit -\n\n" "Losses Available after Loss Surrendered for R & D Credit - -\n\n" " Used in this Computation Against General Profits - - -\n\n" " Losses Carried Back to Earlier Period - Terminal loss\n\n" " claim? [Y/N]\n\n" " Losses Carried Forward - -\n\n" " General Profits Before Other Deductions and Reliefs 17,485\n\n" " Losses Used in this Computation -\n\n" " Carried Back from Later Period [Trade], Current Year [Trade/Property]\n\n" " Profits Chargeable to Corporation Tax 17,485\n\n" "Computation Tax Payable Calculation\n\n" " Financial Years beginning 1 April: Profit Tax Rates\n\n" " 2015 1,485 20% 297.00\n\n" " 2016 16,000 20% 3,200.00\n\n" " Corporation Tax Payable 3,497.00\n\n\n" "Capital Allowances Summary\n\n" " Main Pool Special Rate Pool Single Assets Short Single Assets\n\n" " Life Expensive Cars\n\n" "WDV Brought Forward - - - -\n\n" " Non-FYA - - -\n\n" "Additions FYA @ 100% -\n\n" " AIA Qualifying 1,337 - -\n\n" "AIA Claimed (1,337) - -\n\n" "Disposals - - - -\n\n" "WDA Claimed - - - -\n\n" "Balancing Allowance - - - -\n\n" "Balancing Charge - - - -\n\n" "WDV Carried Forward - - - -\n\n" "For period 01/03/2016 to 28/02/2017 Page 2\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" " Company Tax Return\n\n" "HM Revenue & CT600 (2017) Version 3\n\n" "Customs for accounting periods starting on or after 1 April 2015\n\n" "Your Company Tax Return\n\n" "If we send the company a Notice to deliver a Company Tax Return it has to comply by the filing date or we charge a penalty, even if there\n\n" "is no tax to pay.\n\n" "A return includes a Company Tax Return form, any supplementary pages, accounts, computations and any relevant information. The\n\n" "CT600 Guide tells you how the return must be formatted and delivered. It contains general information you may need to deliver your\n\n" "return, links to more detailed advice and box-by–box guidance for this form and the supplementary pages.\n\n" "The forms in the CT600 series set out the information we need and provide a standard format for calculations.\n\n" "Company information\n\n" "1 Company name Test Case Ltd\n\n" "2 Company registration number 012312244\n\n" "3 Tax reference 123123123\n\n" "4 Type of company\n\n" "About this return\n\n" " This is the above company's return for the period\n\n" "30 from DD/MM/YYYY 35 to DD/MM/YYYY\n\n" " 01/03/2016 ct2017v1 28/02/2017\n\n" " Put an ‘X’ in the appropriate box(es) below\n\n" "40 A repayment is due for this return period\n\n" "45 Claim or relief affecting an earlier period\n\n" "50 Making more than one return for this company now\n\n" "55 This return contains estimated figures\n\n" "60 Company part of a group that is not small\n\n" "65 Notice of disclosable avoidance schemes\n\n" " Transfer pricing\n\n" "70 Compensating adjustment claimed\n\n" "75 Company qualifies for SME exemption\n\n" " Accounts and computations\n\n" "80 I attach accounts and computations for the period to which this return relates X\n\n" "85 I attach accounts and computations for a different period\n\n" "For period 01/03/2016 to 28/02/2017 Page 1\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "About this return continued\n\n" "90 If you are not attaching the accounts and computations, say why not\n\n" " Supplementary pages enclosed\n\n" "95 Loans to participators by close companies - form CT600A\n\n" "100 Controlled foreign companies and foreign permanent establishment exemptions - form CT600B\n\n" "105 Group and consortium - form CT600C\n\n" "110 Insurance - form CT600D\n\n" "115 Charities and Community Amateur Sports Clubs (CASCs) - form CT600E\n\n" "120 Tonnage Tax - form CT600F\n\n" "125 form CT600G (not currently used)\n\n" "130 Cross-border Royalties - form CT600H\n\n" "135 Supplementary charge in respect of ring fence trades - form CT600I\n\n" "140 Disclosure of Tax Avoidance Schemes - form CT600J\n\n" "141 Restitution Tax - form CT600K\n\n" "Tax calculation\n\n" "Turnover\n\n" "145 Total turnover from trade 108,036\n\n" "150 Banks, building societies, insurance companies and other financial concerns –\n\n" " put an ‘X’ in this box if you do not have a recognised turnover and have not made an entry in box 145\n\n" "Income\n\n" "155 Trading profits 34,243\n\n" "160 Trading losses brought forward claimed against profits 16,758\n\n" "165 Net trading profits – box 155 minus box 160 17,485\n\n" "170 Bank, building society or other interest, and profits from -\n\n" " non-trading loan relationships\n\n" "172 Put an ‘X’ in box 172 if the figure in box 170 is net of\n\n" " carrying back a deficit from a later accounting period\n\n" "175 Annual payments not otherwise charged to Corporation Tax -\n\n" " and from which Income Tax has not been deducted\n\n" "For period 01/03/2016 to 28/02/2017 Page 2\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Income continued\n\n" "180 Non-exempt dividends or distributions from non-UK resident companies -\n\n" "185 Income from which Income Tax has been deducted -\n\n" "190 Income from a property business -\n\n" "195 Non-trading gains on intangible fixed assets -\n\n" "200 Tonnage Tax profits -\n\n" "205 Income not falling under any other heading -\n\n" "Chargeable gains\n\n" "210 Gross chargeable gains -\n\n" "215 Allowable losses including losses brought forward -\n\n" "220 Net chargeable gains - box 210 minus box 215 -\n\n" "Profits before deductions and reliefs\n\n" "225 Losses brought forward against certain investment income -\n\n" "230 Non-trade deficits on loan relationships (including interest) and derivative contracts -\n\n" " (financial instruments) brought forward\n\n" "235 Profits before other deductions and reliefs - net sum of boxes 165 to 205 and 220 17,485\n\n" " minus sum of boxes 225 and 230\n\n" "Deductions and reliefs\n\n" "240 Losses on unquoted shares -\n\n" "245 Management expenses -\n\n" "250 UK property business losses for this or previous accounting period -\n\n" "255 Capital allowances for the purposes of management of the business -\n\n" "260 Non-trade deficits for this accounting period from loan relationships and derivative -\n\n" " contacts (financial instruments)\n\n" "For period 01/03/2016 to 28/02/2017 Page 3\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Deductions and reliefs continued\n\n" "265 Non-trading losses on intangible fixed assets -\n\n" "275 Total trading losses of this or a later accounting period 155123\n\n" "280 Put an ‘X’ in box 280 if amounts carried back from later accounting periods are\n\n" " included in box 275\n\n" "290 Non-trade capital allowances -\n\n" "295 Total of deductions and reliefs – total of boxes 240 to 275 and 290 -\n\n" "300 Profits before qualifying donations and group relief – box 235 minus box 295 17,485\n\n" "305 Qualifying donations -\n\n" "310 Group relief -\n\n" "315 Profits chargeable to Corporation Tax – box 300 minus boxes 305 and 310 17,485\n\n" "320 Ring fence profits included -\n\n" "Tax calculation\n\n" "Enter how much profit has to be charged and at what rate\n\n" " Financial Amount of profit Rate of tax Tax\n\n" " year (yyyy) %\n\n" "330 2015 335 1,485 340 20.00% 345 297.00\n\n" " 350 - 355 360 -\n\n" " 365 - 370 375 -\n\n" "380 2016 385 16,000 390 20.00% 395 3,200.00\n\n" " 400 - 405 410 -\n\n" " 415 - 420 425 -\n\n" "Corporation Tax - total of boxes 345, 360, 375, 395, 410 and 425 430 3,497.00\n\n" "Marginal relief for ring fence trades 435 -\n\n" "Corporation Tax chargeable - box 430 minus box 435 440 3,497.00\n\n" "For period 01/03/2016 to 28/02/2017 Page 4\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Reliefs and deductions in terms of tax\n\n" "445 Community investment relief -\n\n" "450 Double taxation relief -\n\n" "455 Put an ‘X’ in box 455 if box 450 includes an underlying Rate relief claim\n\n" "460 Put an ‘X’ in box 460 if box 450 includes any amount carried back from a later\n\n" " period\n\n" "465 Advanced Corporation Tax -\n\n" "470 Total reliefs and deduction in terms of tax - total of boxes 445, 450 and 465 -\n\n" "Calculation of tax outstanding or overpaid\n\n" "475 Net Corporation Tax liability – box 440 minus box 470 3,497.00\n\n" "480 Tax payable on loans and arrangements to participators -\n\n" "485 Put an ‘X’ in box 485 if you completed box A70 in the supplementary pages\n\n" " CT600A\n\n" "490 CFC tax payable -\n\n" "495 Bank levy payable -\n\n" "496 Bank surcharge payable -\n\n" "500 CFC tax, bank levy and bank surcharge payable – total of box 490, 495 and 496 -\n\n" "505 Supplementary charge (ring fence trades) payable -\n\n" "510 Tax chargeable – total of boxes 475, 480, 500 and 505 3,497.00\n\n" "515 Income Tax deducted from gross income included in profits -\n\n" "520 Income Tax repayable to the company -\n\n" "525 Self-assessment of tax payable before restitution tax – box 510 minus box 515 3,497.00\n\n" "527 Restitution tax -\n\n" "528 Self-assessment of tax payable – total of boxes 525 and 527 3,497.00\n\n" "For period 01/03/2016 to 28/02/2017 Page 5\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Tax reconciliation\n\n" "530 Research and Development credit -\n\n" "535 (not currently used)\n\n" "540 Creative tax credit -\n\n" "545 Total of Research and Development credit, and creative tax credit – total boxes 530 -\n\n" " and 540\n\n" "550 Land remediation tax credit -\n\n" "555 Life assurance company tax credit -\n\n" "560 Total land remediation and life assurance company tax credit – total box 550 and -\n\n" " 555\n\n" "565 Capital allowances first-year tax credit -\n\n" "570 Surplus Research and Development credits or creative tax credit payable – box 545 -\n\n" " minus box 525\n\n" "575 Land remediation or life assurance company tax credit payable – total of boxes 545 -\n\n" " and 560 minus boxes 525 and 570\n\n" "580 Capital allowances first-year tax credit payable – boxes 545, 560 and 565 minus -\n\n" " boxes 525, 570 and 575\n\n" "585 Ring fence Corporation Tax included -\n\n" "590 Ring fence supplementary charge included -\n\n" "595 Tax already paid (and not already repaid) -\n\n" "600 Tax outstanding – box 525 minus boxes 545, 560, 565 and 595 3,497.00\n\n" "605 Tax overpaid including surplus or payable credits – total sum of boxes 545, 560, -\n\n" " 565 and 595 minus 525\n\n" "610 Group tax refunds surrendered to this company -\n\n" "615 Research and Development expenditure credits surrendered to this company -\n\n" "For period 01/03/2016 to 28/02/2017 Page 6\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Indicators and information\n\n" "620 Franked investment income/Exempt ABGH distributions -\n\n" "625 Number of 51% group companies -\n\n" " Put an ‘X’ in the relevant boxes, if in the period, the company:\n\n" "630 should have made (whether it has or not) instalment payments under the Corporation Tax (Instalment Payments)\n\n" " Regulations 1998\n\n" "635 is within a group payments arrangement for the period\n\n" "640 has written down or sold intangible assets\n\n" "645 has made cross-border royalty payments\n\n" "Information about enhanced expenditure\n\n" "Research and Development (R&D) or creative enhanced expenditure\n\n" "650 Put an ‘X’ in box 650 if the claim is made by a small or medium-sized enterprise (SME), including a SME subcontractor to\n\n" " a large company\n\n" "655 Put an ‘X’ in box 655 if the claim is made by a large company\n\n" "660 R&D enhanced expenditure -\n\n" "665 Creative enhanced expenditure -\n\n" "670 R&D and creative enhanced expenditure - total of boxes 660 and 665 -\n\n" "675 R&D enhanced expenditure of an SME on work sub contracted to it by a large -\n\n" " company\n\n" "680 Vaccine research expenditure -\n\n" "Land remediation enhanced expenditure\n\n" "685 Enter the total enhanced expenditure -\n\n" "For period 01/03/2016 to 28/02/2017 Page 7\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Information about capital allowances and balancing charges\n\n" "Allowances and charges in calculation of trading profits and losses\n\n" " Capital allowances Balancing charges\n\n" "Annual investment allowance 690 1,337\n\n" "Machinery and plant - special rate pool 695 - 700 -\n\n" "Machinery and plant - main pool 705 1,337 710 -\n\n" "Business premises renovation 715 - 720 -\n\n" "Enterprise zones 721 - 722 -\n\n" "Zero emissions goods vehicles 723 - 724 -\n\n" "Other allowances and charges 725 - 730 -\n\n" "Allowances and charges not included in calculation of trading profits and losses\n\n" " Capital allowances Balancing charges\n\n" "Annual investment allowance 735 -\n\n" "Business premises renovation 740 - 745 -\n\n" "Enterprise zones 746 - 747 -\n\n" "Zero emissions goods vehicles 748 - 749 -\n\n" "Other allowances and charges 750 - 755 -\n\n" "Qualifying expenditure\n\n" "760 Machinery and plant on which first year allowance is claimed -\n\n" "765 Designated environmentally friendly machinery and plant -\n\n" "770 Machinery and plant on long-life assets and integral features -\n\n" "775 Other machinery and plant 1,337\n\n" "For period 01/03/2016 to 28/02/2017 Page 8\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Losses, deficits and excess amounts\n\n" "Amount arising\n\n" " Amount Maximum available for surrender\n\n" " as group relief\n\n" "Losses of trades carried on wholly or partly 780 - 785 -\n\n" "in the UK\n\n" "Losses of trade carried on wholly outside 790 -\n\n" "the UK - special rate pool\n\n" "Non-trading deficits on loan relationships 795 - 800 -\n\n" "and derivative contracts\n\n" "UK property business losses 805 - 810 -\n\n" "Overseas property business 815 -\n\n" "Losses from miscellaneous transactions 820 -\n\n" "Capital losses 825 -\n\n" "Non-trading losses on intangible fixed 830 - 835 -\n\n" "assets\n\n" "Excess amounts\n\n" " Amount Maximum available for surrender\n\n" " as group relief\n\n" "Non-trading capital allowances 840 -\n\n" "Qualifying donations 845 -\n\n" "Management expenses 850 - 855 -\n\n" "For period 01/03/2016 to 28/02/2017 Page 9\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Overpayments and repayments\n\n" "Small repayments\n\n" "860 Do not repay sums of - or less\n\n" " Read the overpayments and repayments section of the Company Tax Return Guide for specific guidance on when and how to\n\n" " make an entry in this box.\n\n" "Repayments for the period covered by this return\n\n" "865 Repayment of Corporation Tax -\n\n" "870 Repayment of Income Tax -\n\n" "875 Payable Research and Development tax credit -\n\n" "880 Payable Research and Development expenditure credit -\n\n" "885 Payable creative tax credit -\n\n" "890 Payable land remediation of life assurance company tax credit -\n\n" "895 Payable capital allowances first-year tax credit -\n\n" "Surrender of tax refund within group\n\n" " Including surrenders under the Instalment Payments Regulations\n\n" "900 The following amount is to be surrendered -\n\n" " Put an 'X' in the appropriate box(es) below\n\n" " the joint Notice is attached 905\n\n" " or\n\n" " will follow 910\n\n" "915 Please stop repayment of the following amount until we send you the Notice -\n\n" "Bank details (for person to whom a repayment is to be made)\n\n" "920 Name of bank or building society\n\n" "925 Branch sort code\n\n" "930 Account number\n\n" "935 Name of account\n\n" "940 Building society reference\n\n" "For period 01/03/2016 to 28/02/2017 Page 10\n" " Rotaready Limited (UTR: 6757612933) IRmark: 4BM4SIXJ6OVED4ZLXHJWOEV7SEG3LULX\n\n" "- Prepared by: Howlader & Co on 16/11/2017 at 09:30\n\n" "Payments to a person other than the company\n\n" "945 Complete the authority below if you want the repayment to be made to a person other than the company\n\n" " I, as (enter status - company secretary, treasurer, liquidator or authorised agent, etc.)\n\n" "950 of (enter company name)\n\n" "955 authorise (enter name)\n\n" "960 of address (enter address)\n\n" " Postcode\n\n" "965 Nominee reference\n\n" " to receive payment on company's behalf\n\n" "970 Name\n\n" "Declaration\n\n" " Declaration\n\n" " I declare that the information I have given on this Company Tax Return and any supplementary pages is correct and complete\n\n" " to the best of my knowledge and belief.\n\n" " I understand that giving false information in the return, or concealing any part of the company’s profits or tax payable, can lead\n\n" " to both the company and me being prosecuted.\n\n" "975 Name\n\n" " James Harvey\n\n" "980 Date DD/MM/YYYY\n\n" " 16/11/2017 16/11/2018\n\n" "985 Status\n\n" " Director\n\n" "For period 01/03/2016 to 28/02/2017 Page 11\n" " ") matches = re.finditer(regex, test_str, re.MULTILINE | re.VERBOSE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and 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 Python, please visit: https://docs.python.org/3/library/re.html