Java Escaping Characters in RegEx

I have the following RegEx email address

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

      

AM is trying to escape characters like below but I am still getting java compilation error. Can someone please help me to avoid the characters in the above RegEx?

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

      

+3


source to share


1 answer


Escaped regex:



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

      

+6


source







All Articles