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]
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!