Analysis of MySQL's method of implementing fuzzy string replacement based on regular expressions

Analysis of MySQL's method of implementing fuzzy string replacement based on regular expressions

This article uses an example to describe how to use MySQL to implement fuzzy string replacement based on regular expressions. Share with you for your reference, the details are as follows:

For example: abcd(efg)hijk after replacement is abcdhijk

Copy the code as follows:
update tabaleA set name = replace(name, substring(name, locate('<contact>', name), locate('</contact>', name)-locate('<contact>'+10, name)),'');

After execution, an error is reported: Truncated incorrect DOUBLE value

The solution is that after querying, it was found that the problem was caused by concat(Str,'') function. Some DBs support the + operator, while others do not and must use the concat function.

Modify the SQL as follows:

Copy the code as follows:
update t_global_project set name = replace(name, substring(name, locate('<contact>', name), locate('</contact>', name)-locate(concat('<contact>','10'), name)),'');

PS: Here are two very convenient regular expression tools for your reference:

JavaScript regular expression online testing tool:
http://tools.jb51.net/regex/javascript

Regular expression online generation tool:
http://tools.jb51.net/regex/create_reg

Readers who are interested in more MySQL-related content can check out the following topics: "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills".

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • Complete guide to using REGEXP regular expressions in MySQL
  • Analysis of the usage of replace and regexp for regular expression replacement in MySQL
  • mysql regular expression LIKE wildcard
  • How to use regular expression query in mysql
  • mysql regular expression query contains non-digits and characters records
  • Detailed explanation of MySQL syntax, special symbols and regular expressions
  • Detailed explanation of MySql basic query, join query, subquery, regular expression query
  • Summary of classic examples of MySQL query operations using regular expressions
  • MySQL Regular Expressions Tutorial
  • Example analysis of the search function of MySQL regular expressions (regexp and rlike)

<<:  Two ways to completely delete users under Linux

>>:  Summary of Vue's common APIs and advanced APIs

Recommend

Detailed explanation of the solution to Ubuntu dual system stuck when starting

Solution to Ubuntu dual system stuck when startin...

Detailed tutorial on installing phpMyAdmin on Ubuntu 18.04

We will install phpMyAdmin to work with Apache on...

Usage instructions for the docker create command

The docker create command can create a container ...

MySQL table field time setting default value

Application Scenario In the data table, the appli...

How to prevent computer slowdown when WIN10 has multiple databases installed

Enable the service when you need it, and disable ...

Implementation of Mysql User Rights Management

1. Introduction to MySQL permissions There are 4 ...

Basic use of subqueries in MySQL

Table of contents 1. Subquery definition 2. Subqu...

Sample code for nginx to achieve dynamic and static separation

1. Simple configuration of nginx's dynamic an...

About MySQL innodb_autoinc_lock_mode

The innodb_autoinc_lock_mode parameter controls t...

How to view Docker container application logs

docker attach command docker attach [options] 容器w...

Nginx monitoring issues under Linux

nginx installation Ensure that the virtual machin...

Docker Detailed Illustrations

1. Introduction to Docker 1.1 Virtualization 1.1....