This works great to disallow all non-English letters:
/[^\x00-\x7F]+/
But I would like to allow these characters:
âäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ
How do I add those to the regex so that they are allowed?
If the pattern like /[^\\x00-\\x7F]+/
works for you, it matches all the letters you now want to avoid matching.
Since the [^...]
is a negated character class , the easiest way to exclude a char/set of chars is to just add them to the class:
/[^\x00-\x7FâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]+/
See the regex demo .
If you use an empty string as the replacement pattern, you will remove every 1+ chars that are not ASCII ( \\x00-\\x7F
) and that are not equal to the letters added to the negated character class.
Though it looks long one but a simple character class would do the job.
Regex: [a-zA-ZâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.