Regex error help

Hi,
I am using the following Regex, which is capturing “Account: Transfer” How to avoid the regex capturing non account numbers? It can be an alphanumeric or just numeric with optional dash and/or dot. This can be in the middle of sentence, so there can be sometext after account number. - Thank you,

(?<=Account #: |Account Number:?|Acct:|Account:|ACCT NO.|Account No.)\s?[A-Za-z0-9-.]+(?=(.*\n)?)

Your current regular expression is designed to capture any alphanumeric sequence (with optional dash and/or dot) that follows certain keywords like “Account #:”, “Account Number:”, “Acct:”, “Account:”, “ACCT NO.”, or “Account No.”. However, it doesn’t limit the match to only account numbers and therefore it’s also capturing “Transfer” if it follows any of these keywords.

To limit the match to only account numbers, you can restrict the characters allowed in the captured sequence. If your account numbers are always numeric with an optional dash and/or dot, you can modify the expression like this:

(?<=Account #: |Account Number:?|Acct:|Account:|ACCT NO.|Account No.)\s?[0-9-.]+(?=(.*\n)?)

This will match any sequence of numbers, dashes, or dots following the specified keywords.

If your account numbers can be alphanumeric but they have a specific pattern (for example, they always start with a letter followed by numbers), you can modify the expression to match this pattern. For example:

(?<=Account #: |Account Number:?|Acct:|Account:|ACCT NO.|Account No.)\s?[A-Za-z][0-9-.]+(?=(.*\n)?)

This will match any sequence that starts with a letter and is followed by numbers, dashes, or dots.

Please note that regular expressions are case sensitive by default. If the keywords can appear in different cases in your text, you may want to add the case-insensitive flag (?i) at the start of your expression:

(?i)(?<=Account #: |Account Number:?|Acct:|Account:|ACCT NO.|Account No.)\s?[A-Za-z][0-9-.]+(?=(.*\n)?)

I hope this helps! If you have any further questions or need more assistance, feel free to ask.

1 Like

Thank you @ManFrancko so much.

Specifically my question is how to include an optional character any where in the pattern. Digits are a must. dash and dot are option. Thank you.

Hi @A_Learner ,

Could you support your Query with Few Sample Data, so that we can clear on what is the expectation ?

The regex is matching the following pattern okay
(<?= Account No.)\s?[A-Za-z0-9-.]+(?=(.*\n)?)

12-1234567-12
12345678 Minimum Pay $1.0
12345678
ABCD12345678
1234-56789
1234-5678.912
A1234-123-B-4678

However if “Account No: Transfer” comes first before “Account No: 12345679”, it is getting “Transfer” which is incorrect. It should not get account number with only alpha.

Thank you,

Hi,

How about the following if numeric character always exists in your target?

 (?<=Account #:\s*|Account Number:?\s*|Acct:\s*|Account:\s*|ACCT NO.\s*|Account No.\s*)[A-Za-z0-9-.]*\d[A-Za-z0-9-.]*(?=(.*\n)?)

Regards,

@A_Learner ,

Do we have a limiter after the Account number value like Transfer, Is there a constant word that we can refer to ?

From the Statements and Samples provided, it looks like it must be Strictly Alphanumeric or Just Numeric, we could check with the below :

(?<=Account No.\s?)([A-Za-z\-.]*[\d.\-]+)+

image

1 Like

Thanks @supermanPunch.

1 Like

Thank you!, @Yoichi.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.