求一正则,可以是所有单词,不包括某些单词

jeezz 2009-11-01 08:12:50
如题所示。
...全文
158 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2009-11-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jeezz 的回复:]
。。。。比如www.baidu.com/(这里可以使所有的英语单词,但是不包括aaa).nsf
[/Quote]

是不包括aaa,还是不能是aaa,也就是下面这个例子是否满足要求
www.baidu.com/baaac.nsf

//不能是aaa
String pattern = "www\\.baidu\\.com/(?!aaa\\.)[^.]+\\.nsf";
//不包括aaa
String pattern = "www\\.baidu\\.com/(?:(?!aaa)[^.])+\\.nsf";
阿_布 2009-11-01
  • 打赏
  • 举报
回复

String url = "www.baidu.com/aaaa.nsf";
boolean b = Pattern.matches("www\\.baidu\\.com/(?!aaa\\.).+\\.nsf",url);
System.out.println(b);
一步一个脚印 2009-11-01
  • 打赏
  • 举报
回复
以前使用正则开发过类似自定义表达式解析运算的模块。

大体思路:
·把要过滤的(也就是不包括的单词),输出成数组或集合的形式。
·使用替换的策略: strStr.replaceAll(filterArray[index],"");
·如果是true/false结果: strStr.matches(filterArray[index].concat("?")); // 我没有测试
·总结来说就是把一个表达式拆成两个表达式。

以上个人意见。。
一步一个脚印 2009-11-01
  • 打赏
  • 举报
回复
以前使用正则开发过类似自定义表达式解析运算的模块。

大体思路:
·把要过滤的(也就是不包括的单词),输出成数组或集合的形式。
·使用替换的策略: strStr.replaceAll(filterArray[index],"");
·如果是true/false结果: strStr.match(filterArray[index].concat("?")); // 我没有测试
·总结来说就是把一个表达式拆成两个表达式。

以上个人意见。。
smartcatiboy 2009-11-01
  • 打赏
  • 举报
回复
冒失用字典之类比较好
jeezz 2009-11-01
  • 打赏
  • 举报
回复
。。。。比如www.baidu.com/(这里可以使所有的英语单词,但是不包括aaa).nsf
x-teamer团队 2009-11-01
  • 打赏
  • 举报
回复
需求描叙非常不到位...
lz12366007 2009-11-01
  • 打赏
  • 举报
回复
正则不好。。。。

62,620

社区成员

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

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