-3

I'm worning on the REGEX pattern to capture the last amount in the row. String looks like:

Ben
1x 1.32 1.32 OK

Mark
3x 0.50 1.50 FAIL

Johny
2x 1.20 2.40 OK

I can't write pattern to capture the last amount. The problem is "OK" and "FAIL" strings after the last amount. I don't know how to handle them by REGEX.

enter image description here

The three dots are just temporary solution to show you how it should works - it should also capture 1.50 amount too.

Please take a look: https://regex101.com/r/vY6hI2/1

pronngo
  • 820
  • 11
  • 26
  • Possible duplicate of [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Sep 20 '16 at 16:22

1 Answers1

1

You can use this pattern:

(\d+(?:\.\d+)?)\s+(?:OK|FAIL)$

It'll work for both decimal and integral values, because of the (?:\.\d+)? element, which makes the decimal point and trailing number optional. The number you want is in capture group 1.

Demo on Regex101 (based on comment)

Sebastian Lenartowicz
  • 4,695
  • 4
  • 28
  • 39