Reputation: 111
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:
^[^.<>(){}'&@#]*$
Upvotes: 0
Views: 65
Reputation: 498
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
Upvotes: 2