Tom
Tom

Reputation: 7223

Is "@" a special character in regular expressions?

I am working on an email filter and I have come across a list of regular expressions that are used to block all emails coming from senders that match a record in that list. While browsing through the list, I have discovered that all occurrences of the @ character are escaped with a \.

Does the @ mean anything special in regular expressions and needs to be escaped like so \@?

Upvotes: 2

Views: 541

Answers (2)

No, the @ is not special character in regex.

The the \ can be use in this meaning

Pattern: \Q...\E

Def Matches the characters between \Q and \E literally, suppressing the meaning of special characters.

Example: \Q+-/\E matches +-/

Upvotes: 1

dcp
dcp

Reputation: 55464

It's normally not a special character, but it doesn't hurt to escape it which is probably why many people do it, they just want to be safe (or they think it's a special character).

Upvotes: 3

Related Questions