Home>Article>Database> Detailed example of using regular expressions to replace content in the database

Detailed example of using regular expressions to replace content in the database

Y2J
Y2J Original
2017-05-23 15:11:49 1859browse

PS: The following is turned over for recording. This is not the original intention of the regular version. It is just using REGEXP. The regular version is more flexible and convenient.

Include the author_url in the comment table into www.sohu .com records, where sohu is replaced with sina, it can be done in one statement~
update comment set author_url=REPLACE(author_url,'sohu','sina') where author_url REGEXP 'www.sohu.com';

Complex replacement with IF judgment

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;

[Related recommendations]

1.Mysql free video tutorial

2.Small Mysql database backup script without virtual host

3.Detailed examples of using mysqldump to back up and restore tables

4.php Detailed example of storing pictures in mysql

5.Detailed example of using mysqldump to back up and restore tables

The above is the detailed content of Detailed example of using regular expressions to replace content in the database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn