[英]Grouping regular expression
Here is my questions: 这是我的问题:
I have a very long string with so many values bounded by the different tags. 我有一个很长的字符串,其中包含由不同标签限定的许多值。 Those values including chinese, english wording and digits.
这些值包括中文,英文字词和数字。
I wanna to separate by specify pattern. 我想按指定模式分开。 The following is an example: (I want to find a pattern xxxxxx where xxxx is chinese, english, digits or any notation but not include "<" or ">" as those two symbol is for identify the tags)
下面是一个示例:(我想找到一个模式xxxxxx,其中xxxx是中文,英语,数字或任何符号,但不包括“ <”或“>”,因为这两个符号用于标识标签)
However, I found some strange for these pattern. 但是,我发现这些模式有些奇怪。 The Pattern seems didn't recgonize the first two tag() but the second one
模式似乎没有重新定义前两个tag(),但是第二个
String a = "<f\"number\">4 <f\"number\"><f$n0>14 <h85><f$n0>4 <f$n0>2 <f$n0>2 7 -<f\"Times-Roman\">7<f\"number\">";
Pattern p = Pattern.compile("<f\"number\">[\\P{sc=Han}*\\p{sc=Han}*[a-z]*[A-Z]*[0-9]*^<>]*<f\"number\">");
Matcher m = p.matcher(a);
while(m.find()){
System.out.println(m.group());
}
The output is as same as my String a 输出与我的String a相同
The character class [\\\\P{sc=Han}*\\\\p{sc=Han}*[az]*[AZ]*[0-9]*^<>]*
matches 0 or more any character because \\\\P{sc=Han}
and \\\\p{sc=Han}
are opposite. 字符类
[\\\\P{sc=Han}*\\\\p{sc=Han}*[az]*[AZ]*[0-9]*^<>]*
匹配0个或多个任何字符,因为\\\\P{sc=Han}
和\\\\p{sc=Han}
是相反的。
I guess you want: 我想你要:
Pattern p = Pattern.compile("<f\"number\">[\\P{sc=Han}a-zA-Z0-9]*<f\"number\">");
You may want to add spaces: 您可能要添加空格:
Pattern p = Pattern.compile("<f\"number\">[\\P{sc=Han}a-zA-Z0-9\s]*<f\"number\">");
or: 要么:
Pattern p = Pattern.compile("<f\"number\">[^<]*<f\"number\">");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.