kellzerIrl
kellzerIrl

Reputation: 101

How to ignore certain characters in regular expression?

I have a regex pattern almost working in Javascript. The only problem is that I don't want to pick up '|' or '&' characters. Here is what I have at the moment.

/^!?[^:(){},'[]+-]+$|[a-zA-Z0-9-_]+/

Can anyone tell me what I need to do to stop the regex picking up these two characters as part of this? Thanks!

Upvotes: 0

Views: 97

Answers (1)

anubhava
anubhava

Reputation: 786291

You can use a negative lookahead to avoid matching these characters in you input:

/^(?![^|&]*[|&])!?[^:(){},'[]+-]+$|[a-zA-Z0-9-_]+/

Upvotes: 1

Related Questions