I have the problem i want to get these numbers, BUT only when then dont come an "foo"
Example: "12:13 Foo" (no) "12:22 Bla" (yes)
i have the Regex: (\d+):(\d+) and dont know what to do that it dont select strings with the "Foo" after the digits
I have the problem i want to get these numbers, BUT only when then dont come an "foo"
Example: "12:13 Foo" (no) "12:22 Bla" (yes)
i have the Regex: (\d+):(\d+) and dont know what to do that it dont select strings with the "Foo" after the digits
This depends somewhat on your regex flavour, but if it supports lookaround you can use:
(\d+):(\d+)(?:\s+(?!Foo)|$)
This doesn't, however, match 12:34Bar
(no space between the 4 and B).
Another edit: If you can use atomic groping, then I think this will cover the cases where there's no space between the last digit and the word following it as well as the previous cases (rubular link):
(\d+):(?>\d+)(?!\s*F[oO][oO])
#Or just (\d+):(?>\d+)(?!\s*Foo) if case-insensitive
(updated answer)
(\d+):(\d+)(?:\s(?!\s*Foo)|$)
By adding a negative lookahead (?!Foo)
, it will only match strings which don't end with "Foo". It will also capture the two digit groups into backreferences 1 and 2.
Matches:
Won't match: