Home  >  Article  >  Database  >  Introduction to the method of fuzzy string replacement in mysql based on regular expressions

Introduction to the method of fuzzy string replacement in mysql based on regular expressions

黄舟
黄舟Original
2017-03-15 17:16:381417browse

This article mainly introduces the mysqlmethod of implementing fuzzy replacement string based on regular expressions. It also compares and analyzes the precautions and related issues of using regular expressions to implement mysql string replacement based on specific examples. For operational skills, friends in need can refer to

This article describes the method of fuzzy replacement of strings based on regular expressions in MySQL. Share it with everyone for your reference, the details are as follows:

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

The code is as follows:

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

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

Solution, after query it was found that it is concat(Str,'')function Error problem, some DBs support +operator, while others cannot and must use the concat function.

Modify the SQL as follows:

The code is as follows:

update t_global_project set name = replace(name, substring(name, 
locate(&#39;<contact>&#39;, name),locate(&#39;</contact>&#39;, name)-locate(concat(&#39;<contact>&#39;,&#39;10&#39;), name)),&#39;&#39;);


The above is the detailed content of Introduction to the method of fuzzy string replacement in mysql based on regular expressions. 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