I would like to use regex to match numbers if a substring is present, but without matching the substring. Hence,
2-4 foo
foo 4-6
bar 8
should match
2, 4
4, 6
I currently have
(\d{0,}\.?\d{1,})
which returns the numbers (int or float). Using
(\d{0,}\.?\d{1,}(?=\sfoo))
only matches 4, rather than 2 and 4. I also tried a lookahead
^(?=.*?\bfoo\b)(\d{0,}\.?\d{1,})
but that matches the 2 only.
*edited typo
2only.\.?be\-?(or-?since not in []) or just.??(?<=\bfoo\b.*)\d*\.?\d+|\d*\.?\d+(?=.*?\bfoo\b)demo.