该字符串如何正则获取符合的字符串 如字符串:I'm from China,I am-# a comp.uter-# enthu.siast-#得到一个数组,里边保存数据如下:am,uter,siast提示,字符串规则,提取前面是空格或者原点 至 -# 之间的字符请问正则如何写??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的规则有问题,如果前面是空格,那from China为什么不提出来呢? public static void main(String[] args) { String content = "I'm from China,I am-# a comp.uter-# enthu.siast-#"; Pattern pattern = Pattern.compile("[^ |.]+(?=-#)"); Matcher matcher = pattern.matcher(content); while(matcher.find()){ System.out.println(matcher.group()); } } 非常感谢 wapigzhu ,如果是这种的呢?China,I :am a :comp uter enthu :siast"如何书写提取 am comp siast 的正则表达式 不知道你具体需求是什么..也不知道你是哪种方式用的这个正则不过\w 单词字符:[a-zA-Z_0-9]也就是说,比如是 China,I :am a :comp*uter enthu :siast那提取出来也是 :am :comp :siast ,而不是:am :comp*uter :siast不知道是不是你想要的结果另外(?::)+\\w*这个效果和:+\w*不是一样的吗 有一种情况不提取,类似":hello" ':hello'这种值提取 :hello 这种,上面代码好像实现不了 你是说':hello'这种不用提取出来是吧?String content ="China,I :am a :comp uter enthu :siast ':hello'"; Pattern p = Pattern.compile("(?<=[^']:)\\w+"); Matcher m = p.matcher(content); while(m.find()){ System.out.println(m.group()); } 如何在2个tomcat中部署的项目之间进行数据通信 不知ACITON 做了什么?? 大家都是如何查找jsp的帮助的? 连接池的困惑,请大伙帮帮忙 在jsp页面播放视频,以wmv文件为例,如何能不让通过查看源文件,看到播放的文件名,即保密。 JAVA BENA 问题,请高手帮忙..谢谢.. 怎么会有90多个java进程? 如何设置log4j的相对输出路径? 经过一个月的努力,终于看见星星了~~散分庆祝一下:) 怎么样把java source file变成.class文件,拜托 brava for java 留言本MVC模式,emplist.jsp 执行后web窗只显示小方框,不显示数据
public static void main(String[] args) {
String content = "I'm from China,I am-# a comp.uter-# enthu.siast-#";
Pattern pattern = Pattern.compile("[^ |.]+(?=-#)");
Matcher matcher = pattern.matcher(content);
while(matcher.find()){
System.out.println(matcher.group());
}
}
China,I :am a :comp uter enthu :siast"如何书写提取 am comp siast 的正则表达式
不过\w 单词字符:[a-zA-Z_0-9]
也就是说,比如是 China,I :am a :comp*uter enthu :siast
那提取出来也是 :am :comp :siast ,
而不是:am :comp*uter :siast
不知道是不是你想要的结果
另外(?::)+\\w*这个效果和:+\w*不是一样的吗
Pattern p = Pattern.compile("(?<=[^']:)\\w+");
Matcher m = p.matcher(content);
while(m.find()){
System.out.println(m.group());
}