Javascript正则表达式不敏感的土耳其字符问题 [英] Javascript regex insensitive turkish character issue

查看:145
本文介绍了Javascript正则表达式不敏感的土耳其字符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用正则表达式过滤某些内容.

i'm using regex for filtering some contents.

var word = new RegExp(filterWord,"gi");// "gi" means Global and insensitive
content = content.replace(word, "");//removes "word" from content

此代码正常工作,但是当正则表达式获取大写字母İ"时,它不会替换单词.

This code works properly but when regex get uppercase "İ" it dont replace word.

例如: 如果

filterWord = istanbul 

content = "İstanbul";

上面的代码无法正常工作,如果我将伊斯坦布尔写给İstanbul,它可以工作,但是这次它并不敏感,我该如何解决这个问题?

Above code not working properly , if i write istanbul to İstanbul ,it is working but this time it is not insensitive , how can i solve this problem ?

推荐答案

regEx 如何与小写和大写字符一起使用是基于十六进制代码的的字符及其在该Unicode集的Unicode联盟中的表示方式(我希望任何语言,因为Unicode都是基于国际标准的.)

How regEx works with Small-Case and Upper-Case chars is based on the Hex-Code of the characters and how they are represented in Unicode consortium of that Unicode set(any language, I hope so as Unicode are based on International Standards).

例如:英语

类似地,我们有

上面带有一些相同颜色的突出显示字符分别是大写和小写字母表示,并且十六进制代码中只有一个差异. Ê的十六进制代码为 00CA ê的十六进制代码为 00EA C E 位于第三位置.

Above are some highlighted characters with same colors are Upper and Small Case representation of their own and there is only one difference in their Hex-code. for Ê Hex-Code is 00CA and for ê is 00EA with one diffrence C and E at third position.

类似地 Ýý 十六进制代码为 00DD u00FD ,只有一个差异 D F

Similarly for Ý and ý Hex-Code is 00DD and u00FD with one difference D and F

现在检查此,例如:

'ÊÌÝêìý'.match(/Ì/gi) //case insensitive
//output ["Ì", "ì"]
'ÊÌÝêìý'.match(/Ì/g) //case sensitive
//output ["Ì"]

'ÊÌÝêìý'.match(/Ý/ig) //case insensitive
//output ["Ý", "ý"]
'ÊÌÝêìý'.match(/Ý/g) //case sensitive
//output ["Ý"]

如果您使用正确的字符,则它应该可以正常工作. 我对拉丁土耳其语字符了解不多.

If you are using right Characters then it should work normally. I don't know much about Latin-Turkish Characters.

这篇关于Javascript正则表达式不敏感的土耳其字符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆