dwilbank
dwilbank

Reputation: 2520

my first lookahead (or lookbehind?) exercise

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.

Upvotes: 0

Views: 140

Answers (2)

h2ooooooo
h2ooooooo

Reputation: 39542

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

should work fine and will only match your numbers.

match result

Regex101 demo

Upvotes: 1

progrenhard
progrenhard

Reputation: 2363

,\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.

Upvotes: 2

Related Questions