Reputation: 3702
I have a string of digits that could vary in length and I want to return only the last 4 digits. Would I use a positive lookback? And use the $ to anchor to?
Upvotes: 1
Views: 92
Reputation: 1261
If your string can be ANY length and you want to match the cases when you have 0 to 3 charaters you should use:
\d?\d?\d?\d?$
or, if the regex engine understands it:
\d{0-4}$
Upvotes: 0