How to remove the first number in a string using a regular expression

To remove a one- or two-digit number located at the beginning of a string, it is efficient to use a regular expression. The following is a regular expression pattern that can be used for this purpose.

^d{1,2}.

The interpretation of this regular expression is as follows

  • ^: denotes the beginning of a string
  • d{1,2}: one or two digits
  • . period (.) character

Thus, this regular expression matches a one- or two-digit number starting at the beginning of a string with a period (.) starting at the beginning of the string and the period (.) immediately following it.

Using this regular expression, it is possible to remove the first “1.” or “12.” from a string such as “1. text” or “12. text,” for example.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top