Maybe it's a simple question but today i'm a bit stucked with it.
I need regex to match only if symbol %
appeared once in a string..
for example:
/regexpForSymbol(%)/.test('50%') => true
/regexpForSymbol(%)/.test('50%%') => false
Thanks!
$ means "Match the end of the string" (the position after the last character in the string).
Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" .
* - means "0 or more instances of the preceding regex token"
You could use:
^[^%]*%[^%]*$
The anchors are there to ensure every character is covered, and you probably already know what [^%]
does.
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