mysql与正则表达式

将comment表中的author_url包含www.sohu.com的记录,其中的sohu替换为sina,一个语句搞定~

update comment set author_url=REPLACE(author_url, 'sohu', 'sina') where author_url REGEXP "www.sohu.com";

带IF判断的复杂替换

update comment set url=IF(url REGEXP "test.yahoo.com.cn",REPLACE(url, 'www1.sohu.com', 'www.sina.com'),REPLACE(url, 'www2.yahoo.com', 'www.sina.com')) where 1=1;

AddThis Social Bookmark Button

相关文档(Relevant Entries)
MySQL十条特殊技巧
如何用命令行SSH备份和恢复MYSQL数据库
修改MYSQL密码和密码破解的常用方法
MySQL自下而上征程 Web应用起飞?
MYSQL数据备份/恢复简易方法
SQL语句优化的原则
如何提高MySQL性能
再谈MySQL升级出现乱码问题的解决
Posted on January 25, 2007 11:46 AM | | | Comments (1) | | TrackBacks (0)

引用地址(TRACKBACKS)
 
TrackBack URL for this entry:
http://www.wujianrong.com/mt-tb.cgi/4491

评论 (1)

发现mysql的正则表达式很"另类"

今天碰到一个问题:

有一组整数用'|'隔开从小到大排列,现要确定某几个数是否在这个string写出mysql的正则表达式.
比如:
'|12|14|16|20|120|130|' 要确定12 16是否在这个string里面 .

最简单的办法是'.*|12|.*|16|.*',但是如果是'12' '14'呢?这个就不行了. '.*|12|.*|14|.*'是不会匹配前面的字符串的, 因为他们相邻,简单的解决办法是改造string用'||'分隔,但这样很浪费空间了.

看了半天manual发现一个很简单的方法'[[::]].*[[::]]' .

[[::]]匹配单词尾部

manual上:

[[::]]
These markers stand for word boundaries. They match the beginning and end of words, respectively. A word is a sequence of word characters that is not preceded by or followed by word characters. A word character is an alphanumeric character in the alnum class or an underscore (_).

同时'曾经未来'给出了一个比较通用的方法.'.*|12|(.*|)*14|.*'

正则表达式的确非常神奇阿.这个也算一题多解吧.


发布评论(ADD YOUR COMMENTS)
 
感谢您参与评论;发表您的意见时请保持文章的相关性;不相关的或是单纯宣传的内容可能会被删掉。您的E-mail只是用来确认您发表的文章,不会出现在网页上。
Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

称呼(Name):      记住我的个人信息(Remember)
邮箱(Email):
网址(URL):
评论(Add your comments):

相关内容
广告计划