perl 正则表达式 如何 不匹配某个 字符串 ?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
liumailong
帖子: 244
注册时间: 2008-02-12 6:41

perl 正则表达式 如何 不匹配某个 字符串 ?

#1

帖子 liumailong » 2011-06-01 2:37

在网上找了半天,都是说如何 不匹配 字符 ,没看到说怎么不匹配 字符串 的。 :em20

比如想匹配除 news 这个单词外的所有字符(包括:new,nsew,se 等)
表达式要怎么写。
:em06
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: perl 正则表达式 如何 不匹配某个 字符串 ?

#2

帖子 eexpress » 2011-06-01 10:12

die if ! /xxx/;
● 鸣学
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: perl 正则表达式 如何 不匹配某个 字符串 ?

#3

帖子 lilydjwg » 2011-06-01 12:16

代码: 全选

(.(?!news))+
头像
liumailong
帖子: 244
注册时间: 2008-02-12 6:41

Re: perl 正则表达式 如何 不匹配某个 字符串 ?

#4

帖子 liumailong » 2011-06-01 17:50

谢谢两位的指点!

我打算在 囗囗囗囗囗囗囗 中用这个正则,试了一下还是不能用。看来 囗囗囗囗囗囗囗 正则和 perl 还是有点不同
头像
tangboyun
帖子: 701
注册时间: 2009-07-25 1:57
联系:

Re: perl 正则表达式 如何 不匹配某个 字符串 ?

#5

帖子 tangboyun » 2011-06-09 20:37

代码: 全选

$text =~ s/(.*?(?=\bnews\b))news/$1/g
https://github.com/tangboyun
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
头像
lexdene
帖子: 434
注册时间: 2010-02-21 16:19
来自: 大连
联系:

Re: perl 正则表达式 如何 不匹配某个 字符串 ?

#6

帖子 lexdene » 2011-06-12 11:51

tangboyun 写了:

代码: 全选

$text =~ s/(.*?(?=\bnews\b))news/$1/g
正则帝。
回复