0
RegExp to return true only when a character appears once. [Solved]
Hi, i've been stuck trying to a solution to this: Eg: var str = "dre3fr@sft"; var str2 = " dre3fr@@sft"; var str3 = "dre3frsft"; I want a regEx that returns true only when a string contains (@) just once: Expected output: regEx.test(str); // true regEx.test(str2); // false regEx.test(str3); // false Thanks in advance.
2 odpowiedzi
+ 3
here is what I got that seems to work, I don't honestly think its the best so please correct me if I'm wrong.
^[^@]*@[^@]*$
the [^@] means anything but @.
0
Thank you @Apollo-Roboto.
That works. I got confused since I was trying to use quantifiers.