Java 什么';“这是跳出此字符串的最佳方法”\b[A-Z0-9.&ux2b;-]&x2B@[A-Z0-9.-]+;\。[A-Z]{2,4}\b“;在爪哇
我将此字符串用于正则表达式Java 什么';“这是跳出此字符串的最佳方法”\b[A-Z0-9.&ux2b;-]&x2B@[A-Z0-9.-]+;\。[A-Z]{2,4}\b“;在爪哇,java,regex,string,escaping,Java,Regex,String,Escaping,我将此字符串用于正则表达式“\b[a-Z0-9.\uz0%+-]+@[a-Z0-9.-]+\.[a-Z]{2,4}\b”,我使用它来检测电子邮件地址 我想知道逃离它的最好方法是什么 我试过很多变化,例如 \\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b \\\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,4}\\\\b 我在@Match注释中使用正则表达式,所以我认为我不能使用StringEscapeUtils。代码
“\b[a-Z0-9.\uz0%+-]+@[a-Z0-9.-]+\.[a-Z]{2,4}\b”
,我使用它来检测电子邮件地址
我想知道逃离它的最好方法是什么
我试过很多变化,例如
\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b
\\\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,4}\\\\b
我在@Match注释中使用正则表达式,所以我认为我不能使用StringEscapeUtils。代码是使用Play框架用Java编写的。但我想这只是一个关于转义Java字符串的问题
public static void signup(
@Match( value=("\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"),
message="Hey there, we need a real email address so we can send you an invite. Thanks :)") String email){
if(validation.hasErrors()) {
params.flash(); // add http parameters to the flash scope
validation.keep(); // keep the errors for the next request
index();
}
else{
Email mail = new Email();
String[] to = {"myemail@me.com", "myemail@gmail.com"};
mail.sendMessage(to, "beta signup", email);
thanks();
}
}
试试这个:
<!--
\b(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])\b
Options: case insensitive; ^ and $ match at line breaks
Assert position at a word boundary «\b»
Match the regular expression below «(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")»
Match either the regular expression below (attempting the next alternative only if this one fails) «[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*»
Match a single character present in the list below «[a-z0-9!#$%&'*+/=?^_`{|}~-]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
One of the characters “!#$%&'*+/=?^_`{|}” «!#$%&'*+/=?^_`{|}»
The character “~” «~»
The character “-” «-»
Match the regular expression below «(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character “.” literally «\.»
Match a single character present in the list below «[a-z0-9!#$%&'*+/=?^_`{|}~-]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
One of the characters “!#$%&'*+/=?^_`{|}” «!#$%&'*+/=?^_`{|}»
The character “~” «~»
The character “-” «-»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"»
Match the character “"” literally «"»
Match the regular expression below «(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match either the regular expression below (attempting the next alternative only if this one fails) «[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]»
Match a single character present in the list below «[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x08 (8 decimal) «\x01-\x08»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x1f (31 decimal) «\x0e-\x1f»
ASCII character 0x21 (33 decimal) «\x21»
A character in the range between ASCII character 0x23 (35 decimal) and ASCII character 0x5b (91 decimal) «\x23-\x5b»
A character in the range between ASCII character 0x5d (93 decimal) and ASCII character 0x7f (127 decimal) «\x5d-\x7f»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «\\[\x01-\x09\x0b\x0c\x0e-\x7f]»
Match the character “\” literally «\\»
Match a single character present in the list below «[\x01-\x09\x0b\x0c\x0e-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x09 (9 decimal) «\x01-\x09»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x7f (127 decimal) «\x0e-\x7f»
Match the character “"” literally «"»
Match the character “@” literally «@»
Match the regular expression below «(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])»
Match either the regular expression below (attempting the next alternative only if this one fails) «(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?»
Match the regular expression below «(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the regular expression below «(?:[a-z0-9-]*[a-z0-9])?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character present in the list below «[a-z0-9-]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “-” «-»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the character “.” literally «\.»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the regular expression below «(?:[a-z0-9-]*[a-z0-9])?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character present in the list below «[a-z0-9-]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “-” «-»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]»
Match the character “[” literally «\[»
Match the regular expression below «(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}»
Exactly 3 times «{3}»
Match the regular expression below «(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)»
Match either the regular expression below (attempting the next alternative only if this one fails) «25[0-5]»
Match the characters “25” literally «25»
Match a single character in the range between “0” and “5” «[0-5]»
Or match regular expression number 2 below (attempting the next alternative only if this one fails) «2[0-4][0-9]»
Match the character “2” literally «2»
Match a single character in the range between “0” and “4” «[0-4]»
Match a single character in the range between “0” and “9” «[0-9]»
Or match regular expression number 3 below (the entire group fails if this one fails to match) «[01]?[0-9][0-9]?»
Match a single character present in the list “01” «[01]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character in the range between “0” and “9” «[0-9]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match the character “.” literally «\.»
Match the regular expression below «(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)»
Match either the regular expression below (attempting the next alternative only if this one fails) «25[0-5]»
Match the characters “25” literally «25»
Match a single character in the range between “0” and “5” «[0-5]»
Or match regular expression number 2 below (attempting the next alternative only if this one fails) «2[0-4][0-9]»
Match the character “2” literally «2»
Match a single character in the range between “0” and “4” «[0-4]»
Match a single character in the range between “0” and “9” «[0-9]»
Or match regular expression number 3 below (attempting the next alternative only if this one fails) «[01]?[0-9][0-9]?»
Match a single character present in the list “01” «[01]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character in the range between “0” and “9” «[0-9]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Or match regular expression number 4 below (the entire group fails if this one fails to match) «[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+»
Match a single character present in the list below «[a-z0-9-]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “-” «-»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the character “:” literally «:»
Match the regular expression below «(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match either the regular expression below (attempting the next alternative only if this one fails) «[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]»
Match a single character present in the list below «[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x08 (8 decimal) «\x01-\x08»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x1f (31 decimal) «\x0e-\x1f»
A character in the range between ASCII character 0x21 (33 decimal) and ASCII character 0x5a (90 decimal) «\x21-\x5a»
A character in the range between ASCII character 0x53 (83 decimal) and ASCII character 0x7f (127 decimal) «\x53-\x7f»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «\\[\x01-\x09\x0b\x0c\x0e-\x7f]»
Match the character “\” literally «\\»
Match a single character present in the list below «[\x01-\x09\x0b\x0c\x0e-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x09 (9 decimal) «\x01-\x09»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x7f (127 decimal) «\x0e-\x7f»
Match the character “]” literally «\]»
Assert position at a word boundary «\b»
-->
此正则表达式实现电子邮件地址的官方标准。就一般目的而言,它可能是有用的
说明:
<!--
\b(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])\b
Options: case insensitive; ^ and $ match at line breaks
Assert position at a word boundary «\b»
Match the regular expression below «(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")»
Match either the regular expression below (attempting the next alternative only if this one fails) «[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*»
Match a single character present in the list below «[a-z0-9!#$%&'*+/=?^_`{|}~-]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
One of the characters “!#$%&'*+/=?^_`{|}” «!#$%&'*+/=?^_`{|}»
The character “~” «~»
The character “-” «-»
Match the regular expression below «(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character “.” literally «\.»
Match a single character present in the list below «[a-z0-9!#$%&'*+/=?^_`{|}~-]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
One of the characters “!#$%&'*+/=?^_`{|}” «!#$%&'*+/=?^_`{|}»
The character “~” «~»
The character “-” «-»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"»
Match the character “"” literally «"»
Match the regular expression below «(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match either the regular expression below (attempting the next alternative only if this one fails) «[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]»
Match a single character present in the list below «[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x08 (8 decimal) «\x01-\x08»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x1f (31 decimal) «\x0e-\x1f»
ASCII character 0x21 (33 decimal) «\x21»
A character in the range between ASCII character 0x23 (35 decimal) and ASCII character 0x5b (91 decimal) «\x23-\x5b»
A character in the range between ASCII character 0x5d (93 decimal) and ASCII character 0x7f (127 decimal) «\x5d-\x7f»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «\\[\x01-\x09\x0b\x0c\x0e-\x7f]»
Match the character “\” literally «\\»
Match a single character present in the list below «[\x01-\x09\x0b\x0c\x0e-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x09 (9 decimal) «\x01-\x09»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x7f (127 decimal) «\x0e-\x7f»
Match the character “"” literally «"»
Match the character “@” literally «@»
Match the regular expression below «(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])»
Match either the regular expression below (attempting the next alternative only if this one fails) «(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?»
Match the regular expression below «(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the regular expression below «(?:[a-z0-9-]*[a-z0-9])?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character present in the list below «[a-z0-9-]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “-” «-»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the character “.” literally «\.»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the regular expression below «(?:[a-z0-9-]*[a-z0-9])?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character present in the list below «[a-z0-9-]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “-” «-»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]»
Match the character “[” literally «\[»
Match the regular expression below «(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}»
Exactly 3 times «{3}»
Match the regular expression below «(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)»
Match either the regular expression below (attempting the next alternative only if this one fails) «25[0-5]»
Match the characters “25” literally «25»
Match a single character in the range between “0” and “5” «[0-5]»
Or match regular expression number 2 below (attempting the next alternative only if this one fails) «2[0-4][0-9]»
Match the character “2” literally «2»
Match a single character in the range between “0” and “4” «[0-4]»
Match a single character in the range between “0” and “9” «[0-9]»
Or match regular expression number 3 below (the entire group fails if this one fails to match) «[01]?[0-9][0-9]?»
Match a single character present in the list “01” «[01]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character in the range between “0” and “9” «[0-9]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match the character “.” literally «\.»
Match the regular expression below «(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)»
Match either the regular expression below (attempting the next alternative only if this one fails) «25[0-5]»
Match the characters “25” literally «25»
Match a single character in the range between “0” and “5” «[0-5]»
Or match regular expression number 2 below (attempting the next alternative only if this one fails) «2[0-4][0-9]»
Match the character “2” literally «2»
Match a single character in the range between “0” and “4” «[0-4]»
Match a single character in the range between “0” and “9” «[0-9]»
Or match regular expression number 3 below (attempting the next alternative only if this one fails) «[01]?[0-9][0-9]?»
Match a single character present in the list “01” «[01]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character in the range between “0” and “9” «[0-9]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Or match regular expression number 4 below (the entire group fails if this one fails to match) «[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+»
Match a single character present in the list below «[a-z0-9-]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “-” «-»
Match a single character present in the list below «[a-z0-9]»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the character “:” literally «:»
Match the regular expression below «(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match either the regular expression below (attempting the next alternative only if this one fails) «[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]»
Match a single character present in the list below «[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x08 (8 decimal) «\x01-\x08»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x1f (31 decimal) «\x0e-\x1f»
A character in the range between ASCII character 0x21 (33 decimal) and ASCII character 0x5a (90 decimal) «\x21-\x5a»
A character in the range between ASCII character 0x53 (83 decimal) and ASCII character 0x7f (127 decimal) «\x53-\x7f»
Or match regular expression number 2 below (the entire group fails if this one fails to match) «\\[\x01-\x09\x0b\x0c\x0e-\x7f]»
Match the character “\” literally «\\»
Match a single character present in the list below «[\x01-\x09\x0b\x0c\x0e-\x7f]»
A character in the range between ASCII character 0x01 (1 decimal) and ASCII character 0x09 (9 decimal) «\x01-\x09»
ASCII character 0x0b (11 decimal) «\x0b»
ASCII character 0x0c (12 decimal) «\x0c»
A character in the range between ASCII character 0x0e (14 decimal) and ASCII character 0x7f (127 decimal) «\x0e-\x7f»
Match the character “]” literally «\]»
Assert position at a word boundary «\b»
-->
您可以在这里找到RFC 2822 我不会讨论“这是电子邮件的正确正则表达式”的问题,只需一句话:你的正则表达式不会接受所有有效的电子邮件地址。见BalusC在评论中给你的 关于转义。Java需要双重转义,因为它首先将正则表达式作为字符串处理,并在创建字符串期间处理所有转义序列。所以,只要避开所有的反斜杠,因为它们需要在替换后出现
\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b
字符类末尾的破折号不需要转义。自2010年5月以来,电子邮件地址可以包含非拉丁字符,如希腊、阿拉伯语、汉语等。我会重新考虑您的正则表达式尝试。如果您只是想玩,可以尝试从外部源代码读入,那么java应该为您完成所有转义。@dann.dev我不明白。电子邮件变量从视图发送到控制器。当你说外部来源时。。。我该怎么做才能逃走呢?很抱歉,我脑子里没有点击。你可以配置Eclipse自动转义你粘贴到字符串中的内容。谢谢你的帮助,但我想我需要解决的问题是转义问题。我可能会在各种不同的正则表达式中遇到这种情况。然后只需使用这个
\\b[A-Z0-9.\%+\-]+@[A-Z0-9.\\-]+\.[A-Z]{2,4}\\b
(你的正则表达式,转义)。
\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b