Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get my regular expression to match

Tags:

.net

regex

It seems to me this should match just fine. Can someone point out to me what I'm doing wrong?

Regular Expression:

^.* ATM DEPOSIT (?'Month'\d{2})-(?'Day'\d{2}) #(?'Reference'[0-9A-Za-z]) .*$

String:

BKOFAMERICA ATM DEPOSIT 07-05 #006475 CUSTOMER 2323 BANK OF AMERICA, SAVANNAH, GA

2 Answers

You are missing a +.

Your expression.

^.* ATM DEPOSIT (?'Month'\d{2})-(?'Day'\d{2}) #(?'Reference'[0-9A-Za-z]) .*$

Correct expression.

^.* ATM DEPOSIT (?'Month'\d{2})-(?'Day'\d{2}) #(?'Reference'[0-9A-Za-z]+) .*$

Apart from that, since you're not interested in anything before the date and after the reference, there is no need to match it. Use:

ATM DEPOSIT (?'Month'\d{2})-(?'Day'\d{2}) #(?'Reference'[0-9A-Za-z]+)
like image 134
Tomalak Avatar answered Dec 08 '25 12:12

Tomalak


You forgot the + at the end of the submatch. It should look like this

(?'Reference'[0-9A-Za-z]+)
like image 34
flec Avatar answered Dec 08 '25 12:12

flec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!