简体   繁体   中英

find and select non-english character in text

我的页面中有一些段落文本用英语和非英语单词组成,我需要用Javascript或jquery查找英语单词,然后在这些单词之前和之后插入。

If you mean non-English character (not word), you can use regular expressions:

if (str.match(/^[a-zA-Z1-9.?!:;\- ]+$/g) === null) 
{
    //str contains non-English character(s) 
    // (You can add more characters to the block if you want to allow more. I may have missed something.)
}

If you mean non-English words, it's a bit more difficult, because then you are required to use some sort of resource (dictionary-like) to match each word. This is much more complicated.

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