-1

I put in online testers the regular expression => .{3}(?<=USD\d{3}) and Subject string => USD100 and this returns 100. I'd like to know is how the regex engine works in this case? How the regex engine returns this 100?

Regular Expression: .{3}(?<=USD\d{3})

Subject: USD100

Returns: 100

Carlos Muñoz
  • 17,397
  • 7
  • 55
  • 80

1 Answers1

1

Your regex means "three characters" (.{3}), plus the additional rule that when you get to the end of the three characters, if you look backward ((?<=...)), you will see "USD" plus three digits (USD\d{3}).

In your input string (USD100), there is only position where you can look backward and see "USD" plus three digits: namely, the very end. So as applied to your input string, your regex effectively means "the three characters just before the very end of the string", i.e. 100.

Does that make sense?

ruakh
  • 175,680
  • 26
  • 273
  • 307