Notepad++ REGEX 3 or 4 digits at the end of string

I want to match the amount of money that is at the very last portion of the string. Some amount of money are in thousands e.g. 1,200.00 and some are only hundreds, e.g. 450.95. The string looks like this "March6March7Globe-Gmovies3dTaguigCity320.00".

Once match, I want to replace the entire string by just the matching value. E.g.

March6March7Globe-Gmovies3dTaguigCity320.00
March6March7Globe-Gmovies3dTaguigCity1,320.00

becomes

320.00
1,320.00

Why is my pattern only matching the thousands matching and not the hundreds? Thanks.

Here's my pattern:

(.*)(\d{1}?\,?\d{3}\.\d{2})
3

2 Answers

Please try: (.*?)((\d,)?\d{3}\.\d{2})

Here, the (*.?) is like (.*), but minimally (the shortest matching string). The comma doesn't have to be escaped.

3
  1. It doesn’t make sense to say \d{1}?.  You want to match one digit, or none, do just say \d?.
  2. So you could use (.*)(\d?\,?\d{3}\.\d{2}).  But that would match the 2019 in City2019.00.  (It would also match the ,243.56 in City,234.56, if you ever got malformed input like that.)  You want to match NNN.NNor N,NNN.NN — you either have N, or you don’t.  So try (.*)((\d\,)?\d{3}\.\d{2}), which makes \d\, (i.e., N,) a group and applies the ? to it.
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like