如何写不包含某指定字串的正则表达式?

devSteven 2004-12-06 03:37:25
比如如果整句中含有"test"就要被过滤掉
...全文
313 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xpony 2005-01-13
  • 打赏
  • 举报
回复
换个角度考虑(供参考)
1、匹配包含 test 的字串
2、对1的结果取非
例如:
------------------------------------
my @aa=("adatesta","aasdtest","a dfeafa");
foreach (@aa) {
print if (not m/test/);
}
-----------------------------------
运行结果:
a dfeafa
xyzxyz1111 2005-01-05
  • 打赏
  • 举报
回复
#!/usr/bin/perl

open (FILE, shift) || die "Data file not specified\n";
while(<FILE>){
s/^((.*test.*)|(.*))$/$3/gmi;
print ;
}
leiyuhou 2005-01-05
  • 打赏
  • 举报
回复
[^test] in perl ?
难道 perl 的正则表达式中语法和其它不一样?这个表示非test这四个字符的任意其它字符。
wti 2004-12-08
  • 打赏
  • 举报
回复
[^test] in perl
devSteven 2004-12-08
  • 打赏
  • 举报
回复
老兄这个是匹配包含test的吗
AllCHN 2004-12-06
  • 打赏
  • 举报
回复
grep (s/^.*test.*$//img) @contents;
$contents =~ s/^.*test.*$//img;
devSteven 2004-12-06
  • 打赏
  • 举报
回复
我只需要一个正则表达式, 不是拿来用在代码里, 谢谢
xyzxyz1111 2004-12-06
  • 打赏
  • 举报
回复
对每一句, 先匹配test,如果匹配成功则删除此句,否则接受这句

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

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