Home > Web Front-end > JS Tutorial > How Can I Match Non-ASCII Characters Using Regular Expressions in JavaScript/jQuery?

How Can I Match Non-ASCII Characters Using Regular Expressions in JavaScript/jQuery?

Patricia Arquette
Release: 2024-12-22 00:12:25
Original
468 people have browsed it

How Can I Match Non-ASCII Characters Using Regular Expressions in JavaScript/jQuery?

Matching Non-ASCII Characters with Regular Expressions

In Javascript/jQuery, matching non-ASCII characters can be a challenge due to the language's limited character support. However, regular expressions offer an effective solution for capturing these characters.

Regex Matching Non-ASCII Characters

The following regular expression can be used to match non-ASCII characters in JavaScript/jQuery:

[^\x00-\x7F]+
Copy after login

This expression matches any character that is not present in the ASCII character set (0-127).

Unicode Matching

Alternatively, you can use Unicode ranges to match non-ASCII characters. For example, the following regex will match characters in the Basic Multilingual Plane:

[^\u0000-\u007F]+
Copy after login

Additional Resources

For further reference:

  • Unicode Range Codes: https://unicode-table.com/en/ranges/
  • Unicode Range Picker for Regular Expressions: https://r12a.github.io/pick/?regex=^x[0000-7FFF]+&bits=128

The above is the detailed content of How Can I Match Non-ASCII Characters Using Regular Expressions in JavaScript/jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template