You want to use \s
instead of \b
. That will look for a whitespace character rather than a word boundary.
If you want your first example of 123 456
to be a match, however, then you will also need to use anchors to accept 123
at the immediate start or end of the string. This can be accomplished via (\s|^)123(\s|$)
. The carat ^
matches the start of the string and $
matches the end of the string.