Updatego_membersetusername = replace (name, 'non-Chinese characters', ''); how to write a non-Chinese character?

Source: Internet
Author: User
Tags mysql update preg
Updatego_membersetusernamereplace (username, & #039; non-Chinese Characters & #039;, & #039; & #039;); I want to replace the database name, replace all the characters in the name that are not numbers, letters, or Chinese characters (that is, remove special characters. What should I do ??? The database is MySQL update go_member set username = replace (username, 'non-Chinese characters ','');

I want to replace the names in the database, as long as the names are not numbers, letters, and Chinese characters (that is, special characters are removed. What should I do ???

The database is MySQL.

Reply content:

Update go_member set username = replace (username, 'non-Chinese characters ','');

I want to replace the names in the database, as long as the names are not numbers, letters, and Chinese characters (that is, special characters are removed. What should I do ???

The database is MySQL.

Mysql Regular Expression Matching. I can test it locally.
update go_member set username= '' where username not REGEXP '[[:alpha:]]|[0-9]|[a-z,A-Z]'

---- Thank you ----
Idea 1 (not recommended): Stupid method: first check all the data, then filter the results (filter non-Chinese characters) data to record the ID of the data, and then update

Idea 2 (recommended): Use the regular expression of SQL, which can also be used in SQL. It depends on the database you are using. the specific database has different syntaxes. It depends on your situation. Google it yourself.
For example, Oracle has four regular expression functions: regexp_like, regexp_replace, regexp_substr, and regexp_instr.
Example:
SelectFrom emp where regexp_like (ename, '^ a [a-z]N $ '); you can find the rows whose names start with a and end with n.

Based on the above solutions, you can explore google by yourself .... Hope to help you.

If PHP is used, it is best to use regular expressions in PHP to match and filter the results. Although MySQL supports regular query statements as mentioned above, the efficiency will be lower.
The Chinese regular expression is:/([u4e00-u9fa5])/uThen, the regular expression used to filter out non-Chinese characters is:/([^u4e00-u9fa5])/u

Provide a Chinese character regular expression in php UTF-8.


  

P: lowercase matches Chinese characters, and P: uppercase matches non-Chinese characters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.