update go_member set username = replace(username,'non-Chinese characters','');
I want to replace the name in the database. As long as the name does not contain numbers, letters or Chinese characters (that is, special characters are removed), all names will be replaced. How to do it? ? ?
The database is MySQL
update go_member set username = replace(username,'non-Chinese characters','');
I want to replace the name in the database. As long as the name does not contain numbers, letters or Chinese characters (that is, special characters are removed), all names will be replaced. How to do it? ? ?
The database is MySQL
mysql regular matching, it is good to try my local testupdate go_member set username= '' where username not REGEXP '[[:alpha:]]|[0-9]|[a-z,A-Z]'
----Thank you for the invitation----
Idea 1 (not recommended): Stupid method, first find out all the data, then filter the results (filter non-Chinese characters) and record the IDs of these data, and then update
Idea 2 (recommended): Use regular expressions in SQL. Regular expressions can also be used in SQL. It depends on what database you use. Specific databases have different syntaxes. This depends on your situation, just Google it. For example, Oracle has these four regular expression functions: regexp_like, regexp_replace, regexp_substr, and regexp_instr.
Example:
select
from emp where regexp_like(ename,'^a[a-z ]n$'); You can find the lines starting with a and ending with n in ename
If you use PHP, it is best to use regular expressions in PHP to match and filter results. Although, as mentioned above, MySQL supports regular query statements, the efficiency will be lower.
The regular rule for Chinese is:
/([u4e00-u9fa5])/u, then the regular rule for filtering non-Chinese is:
/([^u4e00-u9fa5])/u
Provide a Chinese character regular pattern under php utf-8
<code><?php $str = "one中国你好two"; $preg = "/\p{Han}+/u"; $result = preg_replace($preg, '', $str); var_dump($result);</code>