【发布时间】:2016-02-15 05:58:45
【问题描述】:
我正在尝试使用下面的代码在 java 中使用正则表达式从下面的字符串中提取“d320” n-我们; micromax d320 build/kot49h)
String m = "n-us; micromax d320 build/kot49h) ";
String pattern = "micromax (.*)(\\d\\D)(.*) ";
Pattern r = Pattern.compile(pattern);
Matcher m1 = r.matcher(m);
if (m1.find()) {
System.out.println(m1.group(1));
}
但它给我的输出是“d320 build/kot4”,我只想要 d320
【问题讨论】:
-
@TheLostMind 厌倦了过去 2 年一次又一次地发布相同的答案..
-
@TheLostMind 我要从我最喜欢的标签中删除正则表达式。
-
@AvinashRaj - (8000 万开发人员尖叫..).. Nooooooo。上帝啊,这到底是为什么? :P
-
@TheLostMind 许多新人愿意为这个标签做出贡献,例如Stribizhev、vks 等。所以让他们留一条路……别担心,主神 anubhava 仍然在这里观看所有正则表达式问题..
-
现在,
string.replaceFirst("\\bregex+or+string\\b", "django+or+google-app-engine", myfavtags);