简体   繁体   中英

Regex that match with a entire word including Accented caracters

I need to make a regex which searches some words that are invalid in my app.

I have this regex and works good:

/( |\\.|\\,|\\:|\\;|^)(one|two|three|four)( |\\.|\\,|\\:|\\;|$|s|\n)/gi

This will match good;

This text will match with one regex

But this will not:

This text will match with oné regex

How can I build a regex with javascript which includes that exception. That's for an app in spanish.

Regex operates with ascii, therefore special characters are not recognized. You need to explicitly include those into your regex.

/( |\\.|\\,|\\:|\\;|^)(on[eé]|two|three|four)( |\\.|\\,|\\:|\\;|$|s|\n)/gi

A better solution would be to remove all accents from the document before running the regex.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM