Reputation: 43
I need to match account numbers from a large text file. The account numbers will be in the following format:
- Account Number : 123456
- Acct 4567
- Acct Number : 123-456-789
- Account Number 134-456-789
- Account#111111
I need a regex which checks each line starting with “Acc”, ignore white space and any special character and then ending with numeric.
I have written the following regex. The problem is that it matches some of the account number variants. example it matches #1 and #2 but not #3 and #4. The account numbers do not have fixed length and as you can see there are different variants of the string "Account Number"
Any help or advise on fine tuning this will be greatly appreciated.
(Acc[^0-9]*[0-9]*)
Upvotes: 4
Views: 3289
Reputation: 43023
Here is a more precise regex:
^Acc(?:oun)?t(?:\s+Number)?.+[\d-]+$
DEMO: https://regex101.com/r/bM5yB2/4
Upvotes: 6