Regular expression for matching account numbers

c0deblack

I need to match account numbers from a large text file. The account numbers will be in the following format:

  1. Account Number : 123456
  2. Acct 4567
  3. Acct Number : 123-456-789
  4. Account Number 134-456-789
  5. 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]*)
Stephan

Here is a more precise regex:

^Acc(?:oun)?t(?:\s+Number)?.+[\d-]+$

Regular expression visualization

DEMO: https://regex101.com/r/bM5yB2/4

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related