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
+
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 a
s. 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:
[-+]?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With