简体   繁体   English

正则表达式可与包括重音符号在内的整个单词匹配

[英]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 该文本将与onéregex匹配

How can I build a regex with javascript which includes that exception. 如何使用包含该异常的JavaScript构建正则表达式。 That's for an app in spanish. 这是西班牙语的应用程序。

Regex operates with ascii, therefore special characters are not recognized. 正则表达式使用ascii进行操作,因此无法识别特殊字符。 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. 更好的解决方案是在运行正则表达式之前删除文档中的所有重音符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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