I am trying to create a regular expression in JavaScript which contains all alphabet, % and _. I have written this regex for that which is not working fine. Can anyone help me with this?
Here is my Regex:
^[^.<>(){}'&@#]*$
I am trying to create a regular expression in JavaScript which contains all alphabet, % and _. I have written this regex for that which is not working fine. Can anyone help me with this?
Here is my Regex:
^[^.<>(){}'&@#]*$
Here is the regex you are looking for:
const regex = /[A-Za-z_%]/g
Explanation:
/.../ - Javascript regex literal syntax
[...] - A group of possible matches (exp. A or B or C etc.)
A-Za-z - Every English letter. (Upper & lower case)
_ - Underscore char
% - The % char.
g - Global flag suffix to keep matching every res.
You can try it in Regex tester
/PATTERN/, whereas the String literals are the quotes 'String'/"String".