Question

8:9 DAR4:3], 23.98 fps
8:9 DAR4:3], 29.97 fps
8:9 DAR4:3], 25 fps

I've got these 3 possible strings, and I'm looking for an expression that will extract the numbers which occur between the first comma in this line, and the " fps".

either 23.98, 29.97, 25

How best to attack this? Looking behind to whatever digits and dots [\d.] fall before " fps" seems the most logical way but I've never done one of these.

An example, please?

I have this already,

\d{2}\.\d{2}|25

but I'm afraid the "25" could pick up false positives from somewhere later in the text.

Was it helpful?

Solution 2

(?<=, )[0-9]+(\.[0-9]+)?(?= fps)

should work fine and will only match your numbers.

match result

Regex101 demo

OTHER TIPS

,\s*(\d+\.?\d*)\s*fps$

Regular expression visualization

Edit live on Debuggex

Maybe this will work?

  • , indicates the the comma

  • \s* indicates zero or more spaces.

  • (\d+\.?\d*) captures decimal values in a capture group

  • \s* indicates zero or more spaces.

  • fps$ checks to see if fps is at the end of the line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top