Regular Expression – Match any character except +, empty string should also be matched

Add a {0,1} to it so that it will only match zero or one times, no more no less:

[^+]{0,1}

Or, as FailedDev pointed out, ? works too:

[^+]?

As expected, testing with Chrome’s JavaScript console shows no match for "+" but does match other characters:

x = "+"
y = "A"

x.match(/[^+]{0,1}/)
[""]

y.match(/[^+]{0,1}/)
["A"]

x.match(/[^+]?/)
[""]

y.match(/[^+]?/)
["A"]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)