Regular expression: Preceding token is not quantifiable

12,111

+ is a special character, a quantifier, that specifies the multiplicity of the element before. For example a+ means that there should be at least one a, up to any number of as. If you want to match the plus character itself, you will have to escape it:

(-|\+)?

In your case, as you are only considering two different characters, you can also use a character class and specify the two characters that way. Then you don’t need to escape it:

[-+]?
Share:
12,111
VN1992
Author by

VN1992

Updated on June 04, 2022

Comments

  • VN1992
    VN1992 almost 2 years

    I have a regular expression (-|+)?, but when I ran it on regex101.com I get the error:

    +: Preceding token is not quantifiable
    

    What does the error mean? Thank you