Regex to match an optional ‘+’ symbol followed by any number of digits

This should work

\+?\d+

Matches an optional + at the beginning of the line and digits after it

EDIT:

As of OP’s request of clarification: 3423kk55 is matched because so it is the first part (3423). To match a whole string only use this instead:

^\+?\d+$

Leave a Comment