So I'm trying to use regex to take a string like this: "Numbers of 22, 33, 4444"
and extract 22 and 33 from it,
so numbers with a length of 2 and i cant figure it out
at all for some reason, as far as I've gotten is \d\d after messing around for a while
i haven't had a need for regex hardly at all so I'm not exactly used to using it.
\d\d would extract 22, 33, 44, 44 from that string which is not what i would want it to do.
CodePudding user response:
The pattern \b\d{2}\b should work here, assuming the source number list be comma/space separated. Note that most programming languages support a regex find all functionality with which you could use this pattern directly. Here is a demo.
CodePudding user response:
You can achieve this using word boundaries. Regex should be
\b\d\d\b
where \b Matches a word boundary position between a word character and non-word character or position (start / end of string).
