【发布时间】:2012-05-30 05:50:02
【问题描述】:
我想在 Java 中使用正则表达式提取给定字符串中以下字符之间的字符串:
/*
1) Between \" and \" ===> 12222222222
2) Between :+ and @ ===> 12222222222
3) Between @ and > ===> 192.168.140.1
*/
String remoteUriStr = "\"+12222222222\" <sip:+12222222222@192.168.140.1>";
String regex1 = "\"(.+?)\"";
String regex2 = ":+(.+?)@";
String regex3 = "@(.+?)>";
Pattern p = Pattern.compile(regex1);
Matcher matcher = p.matcher(remoteUri);
if (matcher.matches()) {
title = matcher.group(1);
}
我正在使用上面给出的代码 sn-p,它无法提取我想要的字符串。我做错什么了吗?同时,我对正则表达式还很陌生。
【问题讨论】:
标签: java regex pattern-matching matcher