OTUser
OTUser

Reputation: 3848

Java Escaping Characters in RegEx

I have the below RegEx to match email address

[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}

AM trying to escape the characters as below but am still getting java compilation error. Could someone please help me to escape characters in the above RegEx?

String pattern = "\\[-0-9a-zA-Z\\.\\+_\\]\\+@\\[-0-9a-zA-Z\\.\\+_\\]+\\\.\\[a-zA-Z\\]\\{2,4\\}";

Upvotes: 3

Views: 273

Answers (1)

Andie2302
Andie2302

Reputation: 4887

The escaped regex is:

"[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\\.[a-zA-Z]{2,4}"

Upvotes: 6

Related Questions