[问题]求一个正则表达式

软件和网站开发以及相关技术探讨
回复
sanz
帖子: 1010
注册时间: 2006-09-29 5:11

[问题]求一个正则表达式

#1

帖子 sanz » 2008-06-24 10:20

xxxxxxx asdf xxxxx <a href=asdf>xxxxx</a> xxxxxx <tttt asdf tt>

要求只匹配<>外面的asdf,不匹配<>里面的
Dell D620 -> Asus U44SG
Dapper->Edgy->Feisty->Gutsy->Hardy->Karmic->Lucid -> Oneric -> Precise->Trusty
Python+JS
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2008-06-24 10:34

取得标题?
sed 's/<[^<]*>//g'
大概是先把<>去掉不就可以了。
● 鸣学
sanz
帖子: 1010
注册时间: 2006-09-29 5:11

#3

帖子 sanz » 2008-06-24 10:41

不是的,是在php或者mysql里要找到这个asdf
Dell D620 -> Asus U44SG
Dapper->Edgy->Feisty->Gutsy->Hardy->Karmic->Lucid -> Oneric -> Precise->Trusty
Python+JS
头像
nihui
帖子: 1746
注册时间: 2006-10-21 12:03
来自: Shanghai
联系:

#4

帖子 nihui » 2008-06-24 11:26

:D :D

用 negative look ahead 查找前后没有“<”和“>”的“asdf”

代码: 全选

(?!<[^<>]*)asdf(?![^<>]*>)
.

私人空间
附有 Magic Linux 2.1 最新开发日志~


미안하다, 사랑한다


欢迎来 #xfce-cn 中文频道~~
sanz
帖子: 1010
注册时间: 2006-09-29 5:11

#5

帖子 sanz » 2008-06-24 11:48

楼上的表达式在PHP和MYSQL中都报错。
Dell D620 -> Asus U44SG
Dapper->Edgy->Feisty->Gutsy->Hardy->Karmic->Lucid -> Oneric -> Precise->Trusty
Python+JS
头像
greco
帖子: 2487
注册时间: 2007-04-06 10:24
来自: ~/Shanghai

#6

帖子 greco » 2008-06-24 12:07

sanz 写了:楼上的表达式在PHP和MYSQL中都报错。
他让你用 look ahead 嘛,自己查查不就好了
http://silenceisdefeat.com/~greco

代码: 全选

''.join([chr(ord(c)-2) for c in 'O{"G/ockn"ku<"itgeq0ujkBiockn0eqo'])
echo -n "Z3JlY28uc2hpQGdtYWlsLmNvbQ==" | base64 -d
sanz
帖子: 1010
注册时间: 2006-09-29 5:11

#7

帖子 sanz » 2008-06-24 12:56

自己有试验了一下,发现在php中,lookahead 可以实现,但是lookbehind怎么都不行,总是报错。没办法,只能就用lookahead来基本实现该功能了。我把前面的去掉,留后面的一段。
郁闷!
Dell D620 -> Asus U44SG
Dapper->Edgy->Feisty->Gutsy->Hardy->Karmic->Lucid -> Oneric -> Precise->Trusty
Python+JS
回复