Analysis of Fuzzy Replacement String Method Based on Regularity in mysql

  • 2021-07-10 21:01:37
  • OfStack

In this paper, an example is given to describe the method of fuzzy replacement string based on regularity in mysql. Share it for your reference, as follows:

For example: abcd (efg) hijk is replaced by abcdhijk

update tabaleA set name = replace(name, substring(name, locate('<contact>', name),locate('</contact>', name)-locate('<contact>'+10, name)),'');

After execution, error is reported: Truncated incorrect DOUBLE value

The solution, after inquiry, is found to be concat(Str,'') Function error problem, some DB supports + operator, while others cannot be used concat Function.

Amend SQL to read 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 Test Tool:
http://tools.ofstack.com/regex/javascript

Regular expression online generation tool:
http://tools.ofstack.com/regex/create_reg

More readers interested in MySQL can check out the topics on this site: "MySQL Common Functions Summary", "MySQL Log Operation Skills Collection", "MySQL Transaction Operation Skills Collection", "MySQL Stored Procedure Skills Collection" and "MySQL Database Lock Related Skills Collection"

I hope this article is helpful to everyone's MySQL database.


Related articles: