In the first one you can use a variable amount of spaces with (?<=\d{5}: +)
, but like the other answer, it might not be supported by your regex engine.
The last expression doesn't match any string because of the .
on the data, it's not part of the \d
char class, you could use [\d\.]
As a rule of thumb, I always start writing the simplest regex that will do it and I rely on data patterns that I believe will stay.
If you expect the unit to always be after the number you're after, and it will always be bit/s
, there's no reason not to include it as a literal in your regex:
[\d\.]+ bit/s$
Then you can start to turn it into a more complex expression if you find exceptions in your data, like a unit with kbit/s:
(<value>[\d\.]+) *(<unit>\w+)/s$
Using named capture groups so it's easier and more readable to reference them later so can multiply the value by the unit, etc.
In resume: don't use fancier features if you won't really need them.