Skip to content

regular expressions

https://rosettacode.org/wiki/Regular_expressions

https://regex101.com/

http://www.regexr.com/

big mess of my old regex snippets

import re

string = "This is a string"

if re.search('string$', string):
    print("Ends with string.")

string = re.sub(" a ", " another ", string)
print(string)
    $badlist | ForEach-Object {
        Write-Host
        $_ | select *
        $_.name -replace '\\\\hostname\\', ''`
            -replace 'c\$\\folder\\Output\\', ''`
            -replace 'Output\d{3}\\', ''`
            -replace '\\\d{3}_\d{14}\.log'
    } | Get-Unique -OutVariable $fixed
# think this was inside a for loop
        $cleanoutput = $_.ToString() -replace 'bunch of trash text', ""
        $cleanoutput = $cleanoutput.Split(",")
        $regname = [regex]"(?<=\[\\\\hostname\\folder\\folder\\\d{3}Text)(.*?)(?=\\0)"
        $cleanname = $regname.Match($cleanoutput)
        write-host $cleanname
        $html += "<br>"
        $html += $cleanname
        $regtranid = [regex]"(?<=afterthis)(.*?)(?=beforethis)"
        $cleantran = $regtranid.Match($cleanoutput)
        write-host $cleantran
# Character class
. any character except newline
\w \d \s word, digit, whitespace
\W \D \S not word, digit, whitespace
[abc] any of a, b, or c
[^abc] not a, b, or c
[a-g] character between a & g

# Anchors
^abc$ start / end of the string
\b word boundary

# Escaped characters
. * \ escaped special characters
\t \n \r tab, linefeed, carriage return
\u00A9 unicode escaped ©
# Groups & Lookaround
(abc) capture group
\1 backreference to group #1
(?:abc) non-capturing group
(?=abc) positive lookahead
(?!abc) negative lookahead

# Quantifiers & Alternation
a* a+ a? 0 or more, 1 or more, 0 or 1
a{5} a{2,} exactly five, two or more
a{1,3} between one & three
a+? a{2,}? match as few as possible
ab|cd match ab or cd
validate csv, delete all but , and carriage return

[^,|\n\r]

[^~|\n\r]

delete a line containing

find ^.(something).$

replace with nothing

find text between matches

(?<=This is)(.*)(?=sentence)
dokuwiki links

match 4 digits replace w/ wiki link

find only 4 digits \b\d{4}\b

replace with: [[whatever:$&]]

(?P<named_match>...)
(?:invisible group)

(?!negative look-ahead)
(?=positive look-ahead)
(?<!negative look-behind)
(?<=positive look-behind)
email
^[\w-]+(.[\w-]+)@([a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)?.[a-zA-Z]{2,6}|(\d{1,3}.){3}\d{1,3})(:\d{4})?$
(7) or (6)  ^(^[0-9]{6}([0-9]{1})?)?
12345.123   ^\d{5}[\.]\d{3}$    
16 characters   ^.{1,16}$   
Location - 1224th AVE NE LLC    /^124th Ave NE LLC$/    
Location - 2100 Building    /^2100 Building$/   
Dollar Amount   ^[0-9]+((\.[0-9][0-9])||(\.[0-9]))$ 
Anything    ^.{1,100}$  
Special Number  ^[a-zA-Z]{3}[0-9]{9}
Date    (0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d  
Email   ^[\w-]+(\.[\w-]+)*@([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*?\.[a-zA-Z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$    
First Name  ^\w*$   
Full Name   ^\w*$   
Account Number  ^([0-9]{6}[\-][0-9]{3}) 
Account Number  ^[0-9]{2,7} 
Encounter Number    ^[0-9]{3,7} 
Account Number  ^[jJ][0-9]{11}  
Last Name   ^\w*$   
Number  ^[0-9]+$    
Number (10) ^[0-9]{10}  
Number (16) ^[0-9]{16}  
Number (4)  ^[0-9]{4}   
Number (5)  ^[0-9]{5}   
Number (6)  ^[0-9]{6}
Number (7)  ^[0-9]{7}   
Number (7-) ^([0-9]{2}[\-][0-9]{5}) 
Number (8)  ^[0-9]{8}   
Number (9)  ^[0-9]{9}   
Number with a Period(s) ^[jJ][0-9]{11}  
Numbers and Letters Only    ^[a-zA-Z0-9]+$  
One Letter  ^[a-zA-Z]{1}$   
One Letter and 10 Digits Number ^[a-zA-Z]{1}[0-9]{10}   
One Letter and 3 digits Number  ^[a-zA-Z]{1}[0-9]{3}    
Phone Number    ^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$ 
Two Letters ^[a-zA-Z]{2}$   
Account Number  ^\d{6}[\.]\d$   
^([BbWw]{1}[0-9]{11})?  
Zip Code    ^(\d{5}(\d{4})?)?$  

yymmdd 
[0-9][0-9]([0][1-9]|[1][1-2])([0][1-9]|[1-2][0-9]|3[01])
almost right, allows above 31 days
1-31 for days                                 ([1-9]|[12][0-9]|3[01])                      test this with above
Account                                       ^5\d{8}$                                     9 numbers, starts with 5                    
Serial                                        ^\d{1,10}$                                   1 to 10 numeric                             
Amount                                  ^[0-9]*$                                     Dollar amount, no decimal                   
barcode                                       ^[0-25a-zA-Z]${25}                           do not modify                               
Invoice ^\b[\w\d]{8}\b$|^\b[\w\d]{10}\b$|^\b[\w\d... 8, 10 or 12 characters (no spaces)          
DueDate                                       ^\d{2}/\d{2}/\d{4}$                          mm/dd/yyyy                                  
Flag                                      ^[Yy]|[Nn]|[Cc]$                             Y or N or C                                 
Check Amount                                  ^[0-9]*$                                     Dollar amount, no decimal                   
Check Number                                  ^\d{1,10}$                                   1 to 10 numeric                             
Postmark Date                                 ^\d{2}\d{2}\d{4}$                            MMDDYYYY                                    
Due Date                                 ^\d{2}\d{2}\d{4}$                            MMDDYYYY                                    
Contract Number                               ^5\d{8}$                                     9 numbers, starts with 5                    
Invoice Number                                ^\b[\w\d]{8}\b$|^\b[\w\d]{10}\b$|^\b[\w\d... 8, 10 or 12 characters (no spaces)          
Classification                            ^\b31601\b$|^\b31603\b$|^\b31604\b$|^\b31... 5 digits                                    
Gross Amount                                  ^[0-9]*$                                     Dollar amount, no decimal                   
Deduction Amount                              ^[0-9]*$                                     Dollar amount, no decimal                   
Due Amount                        ^[0-9]*$                                     Dollar amount, no decimal                   
Deduction   ^\b1\b$|^\b3\b$|^\b5\b$|^\b6\b$|^\b7\b$|^... 5 digits                                    
Correspondence                                ^[Yy]|[Nn]|[Cc]$                             Y or N or C                                 
Tax     ^\bABL\b$|^\babl\b$|^\bREG\b$|^\breg\b$      ABL or REG                                  
barcode                                       ^[0-25a-zA-Z]${25}                           do not modify                               
Amount                                  ^[0-9]*$                                     Dollar amount, no decimal                   
Check #                                       ^\d{1,20}$                                   1 to 20 digits numeric                      
Account                                       ^[0-9a-zA-Z]{12}$                            12 characters including spaces              
Barcode ^[0-9a-zA-Z]${25}                            do not modify                               
Name                                 ^[\w\d\s]*$                                  Any                                         
Routing                                       ^\d{9}$                                      9 digit numeric                             
Account                                       ^\d{1,12}$                                   1 to 12 numeric                             
Serial                                        ^\d{1,6}$                                    1 to 6 numeric                              
Suspense                                      ^[Yy]|[Nn]$                                  Y or N                                      
Correspondence                                ^[Yy]|[Nn]$                                  Y or N                                      
Routing                                       ^\d{9}$                                      9 digit numeric                             
Account                                       ^\d{1,12}$                                   1 to 12 numeric                             
Serial                                        ^\d{1,6}$                                    1 to 6 numeric                              
Suspense                                      ^[Yy]|[Nn]$                                  Y or N                                      
Correspondence                                ^[Yy]|[Nn]$                                  Y or N                                      
Payer                                         ^[\w\s]{50}$                                 Up to 50 characters                         
Number                                  ^\d{7}$                                      7 digits                                    
Prepared                                 ^\d{6}|\d{2}[/]\d{2}[/]\d{2}$                MMDDYY or MM/DD/YY                          
Corr
Count                                    ^$                                           don't key this field                        
Forms                               ^\d*$                                        Number of enrollment forms in this document 
Number                                  ^\d{7}$                                      7 digits                                    
Date Prepared                                 ^\d{6}|\d{2}[/]\d{2}[/]\d{2}$                MMDDYY or MM/DD/YY                          
Correspondence                                ^[YyNn]$                                     Y or N                                      
Bill Count                                    ^$                                           don't key this field                        
EnrollmentForms                               ^\d*$                                        Number of enrollment forms in this document 
Account Number                                ^[0-9]*$                                     New/Old form. Numbers Only                  
Date Tax Due                                  ^\d{8}|\d{2}[/]\d{2}[/]\d{4}                 New form. MMDDYYYY or MM\DD\YYYY            
Tax Year                                      ^\d{4}$                                      New/Old form. 4 digit year                  
Quarter                                       ^[1-4]{1}$                                   New/Old form. 1, 2, 3, or 4                 
Employees                           ^\d{1,6}$                                    New form. 1 to 6 numeric                    
Wholesaling                            ^[0-9]*$                                     New form. Dollar amount, no decimal         
Correspondence                                ^[YyNn]$                                     Y or N                                      
Barcode                                       ^\d[0-9]{10, 11, 19}$                        Barcode. Do not modify                      
Renewable Fee                                 ^[0-9]*$                                     Dollar amount, no decimal                   
Payer                                         ^[\w\s]{1,50}$                               Up to 50 characters                         
Payer                                         ^\w{20}$                                     Up to 20 characters                         
Invoice Number                                ^\d{1,7}$|^{1}[0]$                           Maximum 7 digits numeric or a zero          
Invoice Amount                                ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Invoice Number                                ^\d{1,7}$|^{1}[0]$                           Maximum 7 digits numeric or a zero          
Invoice Amount                                ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Account                                       ^[1-4]\d{7}|[/*]$                            Star 1-4 8 digits, starting 7 wif 1, 2, 3...
Invoice                                       ^[5-8]\d{9}|[/*]$                            8 digits, starting with 5, 6, 7, 8 or 9, ...
Amount                                        ^\d{1,9}$                                    Dollar amount, no decimal                   
Invoice Number                                ^\d{1,10}$                                   Maximum 10 digits numeric                   
ConsID                                        ^\d{1,7}$                                    Maximum 7 digits numeric                    
Appeal Code                                   ^[\w\d\-]{7,11}$                             7 to 11 characters, alpha, numeric or -     
Correspondence                                ^[YyNn]$                                     Y or N                                      
Gift                                          ^[/*/-]{3}$                                  3 characters, * or -                        
Special Mailer                                ^[YyNn]$                                     Y or N                                      
Paid Amount                                   ^\d{1,9}$                                    Dollar amount, no decimal                   
Serial                                        ^\d{1,4}$                                    Up to 4 digit numeric                       
Payor                                         ^[\w\d\s]*$                                  Any                                         
Date of service                               ^\d{2}[0-1][0-9][0-3][0-9]$                  yymmdd                                      
PatientAccount                                ^(\d{11})$                                   11 digit numeric                            
Paid Amount                                   ^\d{1,9}$                                    Dollar amount, no decimal                   
Name                                          ^\w*[,][\s]?\w*$                             Last,First                                  
Serial                                        ^\d{1,4}$                                    Up to 4 digit numeric                       
Payor                                         ^[\w\d\s]*$                                  Any                                         
Date of service                               ^\d{2}[0-1][0-9][0-3][0-9]$                  yymmdd                                      
PatientAccount                                ^(\d{11})$                                   11 digit numeric                            
Paid Amount                                   ^\d{1,9}$                                    Dollar amount, no decimal                   
Name                                          ^\w*[,][\s]?\w*$                             Last,First                                  
Trust ID                                      ^\w*$                                        .                                           
Employer ID                                   ^\w*$                                        .                                           
Billing ID                                    ^\w*$                                        .                                           
Correspondence                                ^[Y|y|N|n]$                                  Y or N                                      
ES Reference #                                ^\d{9}|\d{12}$                               ES # (9 or 12 digits, no spaces/hyphens)    
Amount Due                                    ^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?... Amount due on form                          
Serial #                                      \d{1,12}                                     Serial # on check (1-12 digits)             
Multi Check Amount                            ^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?... Check amounts in a multi check transaction  
Serial                                        ^\d{1,4}$                                    Up to 4 digit numeric                       
Payor                                         ^[\w\d\s]*$                                  Any                                         
Date of service                               ^\d{2}[0-1][0-9][0-3][0-9]$                  yymmdd                                      
PatientAccount                                ^(\d{11})$                                   11 digit numeric                            
Paid Amount                                   ^\d{1,9}$                                    Dollar amount, no decimal                   
Name                                          ^\w*[,][\s]?\w*$                             Last,First                                  
EmployeeNumber                                (^\d{9}$)                                    9 digit numeric                             
StartDate                                     ^\d{2}/\d{2}/\d{4}$                          mm/dd/yyyy                                  
EndDate                                       ^\d{2}/\d{2}/\d{4}$                          mm/dd/yyyy                                  
Department                                    ^\d{6}$                                      6 digit numeric                             
Name                                          \w*                                          DB Lookup                                   
Reference #                                W*                                           ES #                                        
Amount Due                                    W*                                           Amount due on form                          
Serial #                                      w*                                           Serial # on check                           
Invoice Number                                \b[\d]{8}\b$|^\b[\d]{9}\b$|^\b[\d]{10}\b|... 8,9,10 or 11 digits(no spaces) or C+7 digits
Account Number                                ^\b\d{6}\b$                                  6 digits                                    
Account Name                                  ^[\w\s\d]{1,80}$                             Up to 80 characters                         
Primary Name                                  ^[\w\s]{1,51}$                               FirstName LastName                          
Secondary Name                                ^[\w\s]{1,51}$                               FirstName LastName                          
Client Number                                 ^\d{10}|\d{12}|\d{14}|\d{16}$                10, 12, 14, or 16 digits                    
Designation                                   ^CON|con|ROL|rol|TFI|tfi|CRL|crl$            one of:CON, ROL, TFI, CRL                   
Paid Amount                                   ^\d{2,12}$                                   Digits, no decimal                          
Investment Company                            ^[\w\s\d]{1,80}$                             Up to 80 characters                         
Contribution Year                             ^\d{4}$                                      yyyy                                        
Suspense                                      ^[YyNn]$                                     Y or N                                      
Account                                       ^([U|u][S|s]{2}\d{1,5})|((09)|(10)|(11)|(... Starting with uss and 1-5 digits or up to...
Invoice                                       ^[1]\d{1,5}$                                 Up to 5 digits beginning with 1             
Amount                                        ^\d{1,9}$                                    Dollar amount, no decimal                   
Account                                       ^[fFiIlLpP012]\w{1,14}$                      Up to 15 characters starting with 0,1,2,F...
Payer                                         ^\w*$                                        PayerName                                   
Correspondence                                ^[Yy]$                                       Enter Y for correspondence                  
Suspense                                      ^[Yy]$                                       Enter Y for Susepense                       
CustomerNumber                                ^\d{4,}$                                     Numeric input                               
OrderNumber                                   ^\d{4,}$                                     Numeric input                               
AccountNumber                                 ^\d{4,}$                                     Numeric input                               
Date                                          ^(January|February|March|April|May|June|J... ex: May 8, 2007                             
tax ^\d{10}$|None|Multiple|unknown               Must be 10 digit numeric                    
checkNo                                       ^\d{1,}$                                     Must be numeric                             
checkAmt                                      ^\$?((\d{0,3})[^0-9a-zA-Z]?)*(\d{1,3})[^0... Amount field                                
TaxPayerName                                  \w*                                          anything                                    
Date                                          ^\d{2}/\d{2}/\d{4}$                          mm/dd/yyyy                                  
AccountNumber                                 ^\d{8}$                                      Must be 8 digit numeric                     
Name                                          \w*                                          from database                               
Voucher Number                                ^\d{8}$                                      8 digit voucher #                           
Vendor Number                                 ^\d{4,10}$                                   10 digit vendor #                           
Name                                          ^\w*$                                        Name                                        
SSN                                           (^\d{9}$)                                    nnnnnnnnn                                   
AmountPaid                                    ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Check #                                       ^\d{1,20}$|^[Cc][Aa][Ss][Hh]$                1 to 20 digits numeric                      
Payer Name                                    \W*                                          Check payer name                            
Name                                          \W*[,]\W*                                    Last, First (MI)                            
SID                                           ^\d{3}-\d{2}-\d{4}$                          9 digit numeric                             
Amount                                        ^-?\d[0-9]{1,9}$                             Dollar amount, no decimal                   
micr                                          ^\w*$                                        micr line                                   
tx                                          ^\w*$                                        txId                                        
Valid                                     ^\w*$                                        valid                                       
Serial                                        (^\d{1,16}$)                                 1-16 digits                                 
Amount                                        ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Case                                 ^(1ZT)|(8YT)|(9YT)|([xX]YT)\d{6}$            1ZT + six digits                            
LicensePlate                                  ^([A-Za-z]{3}\d{3} | \d{3}[A-Za-z]{3})$      nnn-999 or 999-nnn                          
CaseOption                                    ^([Pp]|[Mm]|[Cc]|[Oo]|[Mm]{2}|[Cc]|[Cc][M... P,M,Mm,C,CM,O,S                             
Correspondence                                ^[Yy]$                                       Enter Y for correspondence                  
Batch Posted Date                             ^\d{2}/\d{2}/\d{4}$                          mm/dd/yyyy                                  
Batch Number                                  ^\d*$                                        Numeric                                     
Control Number                                ^[Pp]?[0-9]+$                                (P) 5-6 Digits                              
Check #                                       ^\d*$                                        Check #                                     
Check Amount                                  ^-?\d[0-9]{0,9}$                             Dollar Amount, No Decimal                   
Bank Transit Routing                          ^-?\d[0-9]{0,9}$                             Dollar Amount, no decimal                   
Bank Account                                  ^-?\d[0-9]{0,9}$                             Dollar Amount, no decimal                   
Output File                                   \W*                                          ####Day#                                    
Check Date                                    ^\d{2}/\d{2}/\d{4}$                          mm/dd/yyyy                                  
Customer Number                               [TRN]{3}\d{2}                                Customer Number                             
Customer Name                                 \W*                                          Customer Name                               
ATTN                                          \W*                                          ATTN                                        
Invoice Number                                ^[T]\d{7}$                                   Invoice number                              
Invoice Date                                  ^\d{2}/\d{2}/\d{4}$                          Invoice Date DD/MM/YYYY                     
Invoice Due Date                              ^\d{2}/\d{2}/\d{4}$                          Invoice Due Date DD/MM/YYYY                 
Permit Number                                 \W*                                          Permit Number                               
Bill Type                                     \W*                                          Bill Type                                   
City                                          \w+                                          City Name                                   
Tax Parcel                                    \w+                                          Parcel #                                    
Auditor File                                  \w+                                          Auditor #                                   
WO or ER #                                    \w+                                          WO or ER #                                  
Section                                       ^-?\d{1,2}$                                  1 or 2 digit #                              
Township                                      ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Range                                         ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Customer Number                               [TRN]{3}\d{2}                                Customer Number                             
Customer Name                                 \W*                                          Customer Name                               
ATTN                                          \W*                                          ATTN                                        
Invoice Number                                ^[T]\d{7}$|^[T]\d{7}\w{2}$                   Invoice #: T1234567(AA)                     
Invoice Date                                  ^\d{2}/\d{2}/\d{4}$                          Invoice Date MM/DD/YYYY                     
Invoice Due Date                              ^\d{2}/\d{2}/\d{4}$                          Invoice Due Date MM/DD/YYYY                 
Permit Number                                 \W*                                          Permit Number                               
Bill Type                                     \W*                                          Bill Type                                   
HP Line Name                                  \w+                                          City Name                                   
Tax Parcel                                    \w+                                          Parcel #                                    
Auditor File                                  \w+                                          Auditor #                                   
WO or ER #                                    \w+                                          WO or ER #                                  
Section                                       ^-?\d{1,2}$                                  1 or 2 digit #                              
Township                                      ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Range                                         ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
County                                        \w+                                          County                                      
Permit #                                      \w+                                          Permit #                                    
Highway #                                     \w+                                          Highway # #                                 
Milepost #                                    \w+                                          Milepost #                                  
Section                                       ^-?\d{1,2}$                                  1 or 2 digit #                              
Township                                      ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Range                                         ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
County                                        \w+                                          County                                      
Permit#                    \w+                                          Permit/Utility/Franchise #                  
Highway/SR #                                  \w+                                          Highway/SR # #                              
Milepost #                                    \w+                                          Milepost #                                  
Section                                       ^-?\d{1,2}$                                  1 or 2 digit #                              
Township                                      ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Range                                         ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
State                                         \w+                                          State                                       
Permit#                                       \w+                                          Permit#                                     
County                                        \w+                                          County                                      
Pipe Size #                                   \w+                                          Pipe Size #                                 
Section                                       ^-?\d{1,2}$                                  1 or 2 digit #                              
Township                                      ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Range                                         ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Title                                         \w+                                          Title                                       
County                                        \w+                                          County                                      
Auditor File                                  \w+                                          Auditor File                                
Parcel #                                      \w+                                          Parcel #                                    
Section                                       ^-?\d{1,2}$                                  1 or 2 digit #                              
Township                                      ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Range                                         ^-?\d[0-9]{0,1}$                             1 or 2 digit #                              
Street                                        W*                                           Street, Located on top left of card         
Permit Number                                 W*                                           Issued Permit # (Left most column)          
Name                                          w*                                           Name of Company or Individual (next to pe...
Address                                       W*                                           Address # (next to name column)             
Transaction Date                              ^\d{6}$                                      YYMMDD                                      
Sub Batch Number                              ^\d{6}-[A-Z]{3}-[A-Z]{1}-\d{3}$              YYMMDD-AAA-A-###                            
PatientNumber                                 ^([R][P]\d{9})$|^\d{7,11}$                   Must be 7-11 digit numeric or RP with 9 d...
Transaction Date                              ^\d{6}$                                      YYMMDD                                      
Sub Batch Number                              ^\d{6}-[A-Z]{3}-[A-Z]{1}-\d{3}$              YYMMDD-AAA-A-###                            
PatientNumber                                 ^([R][P]\d{9})$|^\d{7,11}$                   Must be 7-11 digit numeric or RP with 9 d...
Address                                       W*                                           Address, Located on top left                
Permit Number                                 W*                                           Issued Permit #                             
Name                                          w*                                           Name of Company or Individual               
Annual Date                                   w*                                           Most Recent Date Invoiced                   
Claim Number                                  [C][-]\d{5}                                  Claim # (C-XXXXX)                           
Date Processed                                ^\d{2}\d{2}\d{2}$                            Invoice Date YYMMDD                         
Patient Number                                ^\d{7,11}$                                   Numeric input, 7 digits                     
Patient Name                                  \W*                                          Patient Name                                
Date Processed                                ^\d{2}\d{2}\d{2}$                            Invoice Date YYMMDD                         
Patient Number                                ^\d{7,11}$                                   Numeric input, 7 digits                     
Patient Name                                  \W*                                          Patient Name                                
Donor ID                                      \w*                                          Anything                                    
Appeal Code                                   \w*                                          Anything                                    
Paid Amount                                   ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Account Number                                \w*                                          Anything                                    
SSC Amount Due                                \w*                                          Anything                                    
Check Amount                                  ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Dept Number                                   \w*                                          Alpha-Numeric                               
Maker Name                                    \w*                                          Alpha-Numeric                               
Memo Line                                     \w*                                          Alpha-Numeric                               
Check Amount                                  ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
PatientAccount                                (^\d{7,12}$)                                 Between 7 and 12 digits                     
DateOfService                                 \d{2}/\d{2}/\d{4}                            mm/dd/yyyy                                  
AmountPaid                                    ^-?\d[0-9]{1,9}$                             dollar amount, no decimal                   
Name                                          \W*[,]\W*                                    Last, First (MI)                            
Check #                                       ^\d{1,20}$|^[Cc][Aa][Ss][Hh]$                1 to 20 digits numeric                      
Payer Name                                    \W*                                          Check payer name                            
Payer                                         ^[\w\s]{1,50}$                               Up to 50 characters                         
PayerName                                     \w*                                          Apha-Numeric                                
Amount                                        \d{0,6}\.\d{1,2}                             Decimal (6.2)                               
SubscriberId                                  ^\b(?!WQZ)[\w\d]{1,12}$                      Alpha-Numeric, up to 12                     
SubscriberName                                ^[\w\s,]{1,100}$                             1 to 100 characters                         
SubscriberSSN                                 ^[\d]{9}$                                    9 digits                                    
MemberName                                    ^[\w\s,]{1,100}$                             1 to 100 characters                         
Group
ProviderName                                  ^[\w\s,]{1,100}$                             1 to 100 characters                         
ProviderTIN                                   ^[\w\d]{1,9}$                                1 to 9 Alpha-Numeric                        
ClaimNumber                                   ^[\w\d]{1,10}$                               1 to 10 Alpha-Numeric                       
DateOfService                                 ^\d{2}\d{2}\d{4}$                            mmddyyyy                                    
Document_Type                                 ^[\w\s]{1,50}$                               1 to 50 characters                          
CheckNumber                                   ^\d*$                                        Check #                                     
CheckAmount                                   ^-?\d[0-9]{0,9}$                             Dollar Amount, No Decimal                   
SubscriberId                                  ^[\w\d]{1,12}$                               Alpha-Numeric, up to 12                     
SubscriberName                                ^[\w\s,]{1,100}$                             1 to 100 characters                         
SubscriberSSN                                 ^[\d]{9}$                                    9 digits                                    
MemberName                                    ^[\w\s,]{1,100}$                             1 to 100 characters                         
GroupNumber                                   ^[\w\d]{1,8}$                                1 to 8 Alpha-Numeric                        
ProviderName                                  ^[\w\s,]{1,100}$                             1 to 100 characters                         
ProviderTIN                                   ^[\w\d]{1,9}$                                1 to 9 Alpha-Numeric                        
ClaimNumber                                   ^[\w\d]{1,10}$                               1 to 10 Alpha-Numeric                       
DateOfService                                 ^\d{2}\d{2}\d{4}$                            mmddyyyy                                    
Document_Type                                 ^[\w\s]{1,50}$                               1 to 50 characters                          
CheckNumber                                   ^\d*$                                        Check #                                     
CheckAmount                                   ^-?\d[0-9]{0,9}$                             Dollar Amount, No Decimal 

credit cards http://stackoverflow.com/questions/9315647/regex-credit-card-number-tests

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$

used with the output of an old version of softperfect network mapper

$hosts = $netmap.'network-scanner-result'.devices.item.hostname | out-file 'c:\backup\index\hosts.txt'
invoke-item 'c:\backup\index\hosts.txt'
foreach($_ in $hosts)
$adminshare = "`\`\$host`\c`$`\folder"

find: ^.*
replace: \\\\$&\\c\$\\
used with 
C:\backup\index\hosts.txt

https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm

http://regex.inginf.units.it/

Regular Expressions Cheat Sheet by Dave Child (DaveChild) via cheatography.com/1/cs/5/

Anchors
^ Start of string, or start of line in multi-line
pattern
\A Start of string
$ End of string, or end of line in multi-line
pattern
\Z End of string
\b Word boundary
\B Not word boundary
\< Start of word
\> End of word
Character Classes
\c Control character
\s White space
\S Not white space
\d Digit
\D Not digit
\w Word
\W Not word
\x Hexadecimal digit
\O Octal digit
POSIX
[:upper:] Upper case letters
[:lower:] Lower case letters
[:alpha:] All letters
[:alnum:] Digits and letters
[:digit:] Digits
[:xdigit:] Hexadecimal digits
[:punct:] Punctuation
[:blank:] Space and tab
[:space:] Blank characters
[:cntrl:] Control characters
[:graph:] Printed characters
[:print:] Printed characters and spaces
[:word:] Digits, letters and underscore
Assertions
?= Lookahead assertion
?! Negative lookahead
?<= Lookbehind assertion
?!= or ?<! Negative lookbehind
?> Once-only Subexpression
?() Condition [if then]
?()| Condition [if then else]
?# Comment
Quantifiers
* 0 or more {3} Exactly 3
+ 1 or more {3,} 3 or more
? 0 or 1 {3,5} 3, 4 or 5
Add a ? to a quantifier to make it ungreedy.
Escape Sequences
\ Escape following character
\Q Begin literal sequence
\E End literal sequence
"Escaping" is a way of treating characters
which have a special meaning in regular
expressions literally, rather than as special
characters.
Common Metacharacters
^ [ . $
{ * ( \
+ ) | ?
< >
The escape character is usually \
Special Characters
\n New line
\r Carriage return
\t Tab
\v Vertical tab
\f Form feed
\xxx Octal character xxx
\xhh Hex character hh
Groups and Ranges
. Any character except new line (\n)
(a|b) a or b
(...) Group
(?:...) Passive (non-capturing) group
[abc] Range (a or b or c)
[^abc] Not (a or b or c)
[a-q] Lower case letter from a to q
[A-Q] Upper case letter from A to Q
[0-7] Digit from 0 to 7
\x Group/subpattern number "x"
Ranges are inclusive.
Pattern Modifiers
g Global match
i * Case-insensitive
m * Multiple lines
s * Treat string as single line
x * Allow comments and whitespace in
pattern
e * Evaluate replacement
U * Ungreedy pattern
* PCRE modifier
String Replacement
$n nth non-passive group
$2 "xyz" in /^(abc(xyz))$/
$1 "xyz" in /^(?:abc)(xyz)$/
$` Before matched string
$' After matched string
$+ Last matched string
$& Entire matched string
Some regex implementations use \ instead of $.
By Dave Child (DaveChild)
cheatography.com/davechild/
www.addedbytes.com
Published 19th October, 2011.
Last updated 2nd January, 2015.
Page 1 of 1.
Sponsored by ApolloPad.com
Set Your Pen Free and Finish Your Novel!
https://apollopad.com
Anchors
^abc$ start / end of the string
\b word boundary

Escaped characters
. * \ escaped special characters
\t \n \r tab, linefeed, carriage return
\u00A9 unicode escaped ©
#Groups & Lookaround
(abc) capture group
\1 backreference to group #1
(?:abc) non-capturing group
(?=abc) positive lookahead
(?!abc) negative lookahead

Quantifiers & Alternation
a* a+ a? 0 or more, 1 or more, 0 or 1
a{5} a{2,} exactly five, two or more
a{1,3} between one & three
a+? a{2,}? match as few as possible
ab|cd match ab or cd

nul in notepad
\x00
-------------------------------------------------------------------------------------
for wiki remove \\ after headings
(?<=\=\=)\\\\
delete a line containing

find ^.(something).$
replace with nothing

find text between matches

(?<=This is)(.*)(?=sentence)

```sh
Basic matching:
    req.url ~ "searchterm"
    True if req.url contains "searchterm" anywhere.

    req.url == "searchterm"
    True if req.url is EXACTLY searchterm

Matching at the beginning or end of a string
    req.http.host ~ "^www."
    True if req.http.host starts with "www" followed by any single
    character.

    req.http.host ~ "^www\."
    True if req.http.host starts with "www.". Notice that . was
    escaped.

    req.url ~ "\.jpg$"
    True if req.url ends with ".jpg"

Multiple matches
    req.url ~ "\.(jpg|jpeg|css|js)$"
    True if req.url ends with either "jpg", "jpeg", "css" or "js".

Matching with wildcards
    req.url ~ "jp.g$"
    True if req.url ends with "jpeg", "jpag", "jp$g" and so on, but NOT
    true if it ends with "jpg".

    req.url ~ "jp.*g$"
    True if req.url ends with "jpg", "jpeg", "jpeeeeeeeg",
    "jpasfasf@@!!g" and so forth (jp followed by 0 or more random
    characters ending with the letter 'g').

Conditional matches
    req.url ~ "\.phg(\?.*)?$"
    True if req.url ends with ".php" ".php?foo=bar" or ".php?", but not
    ".phpa". Meaning: Either it ends with just ".php" or ".php"
    followed by a question mark any any number of characters.

    req.url ~ "\.[abc]foo$"
    True if req.url ends with either ".afoo" ".bfoo" or ".cfoo".

    req.url ~ "\.[a-c]foo$"
    Same as above.

Replacing content
    set req.http.host = regsub(req.http.host, "^www\.","");
    Replaces a leading "www." in the Host-header with a blank, if
    present.

    set req.http.x-dummy = regsub(req.http.host, "^www.","leading-3w.");
    Sets the x-dummy header to contain the host-header, but replaces
    a leading "www." with "leading-3w" example:

    Host: www.example.com =>
        Host: www.example.com
        X-Dummy: leading-3w.example.com

    Host: example.com =>
        Host: example.com
        X-Dummy: example.com


  credit cards http://stackoverflow.com/questions/9315647/regex-credit-card-number-tests
  ^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$

- ----------------------------
  find replace

hosts admin share collector

# collect and index all admin shares index for qtab
$hosts = $netmap.'network-scanner-result'.devices.item.hostname | out-file 'c:\backup\index\hosts.txt'
invoke-item 'c:\backup\index\hosts.txt'
foreach($_ in $hosts)
$adminshare = "`\`\$host`\c`$`\boop"

find: ^.*
replace: \\\\$&\\c\$\\
used with
C:\backup\index\hosts.txt



https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm
http://regex.inginf.units.it/


Regular Expressions Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/5/
Anchors
^ Start of string, or start of line in multi-line
pattern
\A Start of string
$ End of string, or end of line in multi-line
pattern
\Z End of string
\b Word boundary
\B Not word boundary
\< Start of word
\> End of word
Character Classes
\c Control character
\s White space
\S Not white space
\d Digit
\D Not digit
\w Word
\W Not word
\x Hexadecimal digit
\O Octal digit
POSIX
[:upper:] Upper case letters
[:lower:] Lower case letters
[:alpha:] All letters
[:alnum:] Digits and letters
[:digit:] Digits
[:xdigit:] Hexadecimal digits
[:punct:] Punctuation
[:blank:] Space and tab
[:space:] Blank characters
[:cntrl:] Control characters
[:graph:] Printed characters
[:print:] Printed characters and spaces
[:word:] Digits, letters and underscore
Assertions
?= Lookahead assertion
?! Negative lookahead
?<= Lookbehind assertion
?!= or ?<! Negative lookbehind
?> Once-only Subexpression
?() Condition [if then]
?()| Condition [if then else]
?# Comment
Quantifiers
* 0 or more {3} Exactly 3
+ 1 or more {3,} 3 or more
? 0 or 1 {3,5} 3, 4 or 5
Add a ? to a quantifier to make it ungreedy.
Escape Sequences
\ Escape following character
\Q Begin literal sequence
\E End literal sequence
"Escaping" is a way of treating characters
which have a special meaning in regular
expressions literally, rather than as special
characters.
Common Metacharacters
^ [ . $
{ * ( \
+ ) | ?
< >
The escape character is usually \
Special Characters
\n New line
\r Carriage return
\t Tab
\v Vertical tab
\f Form feed
\xxx Octal character xxx
\xhh Hex character hh
Groups and Ranges
. Any character except new line (\n)
(a|b) a or b
(...) Group
(?:...) Passive (non-capturing) group
[abc] Range (a or b or c)
[^abc] Not (a or b or c)
[a-q] Lower case letter from a to q
[A-Q] Upper case letter from A to Q
[0-7] Digit from 0 to 7
\x Group/subpattern number "x"
Ranges are inclusive.
Pattern Modifiers
g Global match
i * Case-insensitive
m * Multiple lines
s * Treat string as single line
x * Allow comments and whitespace in
pattern
e * Evaluate replacement
U * Ungreedy pattern
* PCRE modifier
String Replacement
$n nth non-passive group
$2 "xyz" in /^(abc(xyz))$/
$1 "xyz" in /^(?:abc)(xyz)$/
$` Before matched string
$' After matched string
$+ Last matched string
$& Entire matched string
Some regex implementations use \ instead of $.
By Dave Child (DaveChild)
cheatography.com/davechild/
www.addedbytes.com
Published 19th October, 2011.
Last updated 2nd January, 2015.
Page 1 of 1.
Sponsored by ApolloPad.com
Set Your Pen Free and Finish Your Novel!
https://apollopad.com