问个正则的问题

Brunhild 2008-07-17 05:03:36
有字符串xxxxx/yyyyy@zzzzzz
如何取/和@之间的内容?
...全文
130 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Brunhild 2008-07-17
  • 打赏
  • 举报
回复
非常感谢
logi22 2008-07-17
  • 打赏
  • 举报
回复
预匹配
craky 2008-07-17
  • 打赏
  • 举报
回复
9楼可行
hoszone 2008-07-17
  • 打赏
  • 举报
回复
String str = "xxxx/yyyyy@zzzzzz";
String regex = "\\/(.*?)\\@";

Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);

while(m.find())
{
System.out.println(m.group(1));
}
把楼上一个兄弟的改造了一下,不知道是否可行??
craky 2008-07-17
  • 打赏
  • 举报
回复
正等你来呢,哈哈
lovingprince 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 joejoe1991 的回复:]
Java code Pattern pat = Pattern.compile("/(.+?)@");
Matcher mat = pat.matcher("xxxxx/yyyyy@zzzzzz ");
while (mat.find()) {
System.out.println(mat.group(1));
}
[/Quote]


正解,非常好,呵呵。
joejoe1991 2008-07-17
  • 打赏
  • 举报
回复
		Pattern pat = Pattern.compile("/(.+?)@");
Matcher mat = pat.matcher("xxxxx/yyyyy@zzzzzz ");
while (mat.find()) {
System.out.println(mat.group(1));
}
Brunhild 2008-07-17
  • 打赏
  • 举报
回复
3楼,能不能直接用正则解决,我不想再截头截尾?
Brunhild 2008-07-17
  • 打赏
  • 举报
回复
谢谢2楼,不过不是要分割,是直接取出中间的部分
craky 2008-07-17
  • 打赏
  • 举报
回复

String str = "xxxx/yyyyy@zzzzzz";
String regex = "\\/.*?\\@";

Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);

while(m.find())
{
System.out.println(str.substring(m.start() + 1, m.end() - 1));
}
craky 2008-07-17
  • 打赏
  • 举报
回复

String str = "xxxx/yyyyy@zzzzzz";
String regex = "\\/|\\@";
String[] strs = str.split(regex);

for(String s: strs)
{
System.out.println(s);
}

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧