为什么此正则表达式返回true? [英] Why does this regex return true?

查看:165
本文介绍了为什么此正则表达式返回true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么此正则表达式返回true?

Why does this regex return true?

Regex.IsMatch("العسكرية", "العسكري")

我用谷歌搜索,没有任何反应.

I googled and nothing came up.

推荐答案

我怀疑您发布的内容实际上是相反的,其中较短的文本实际上是模式,而较长的输入是与之匹配的输入.在这种情况下,由于模式会匹配单词中除最后一个字母以外的所有内容,因此这将返回true.

I suspect what you posted is actually reversed, where the shorter text is in fact the pattern, and the longer input is the input being matched against. In that case, this would return true since the pattern matches everything but the last letter in the word.

为清楚起见,العسكري是模式,العسكرية是输入.由于我知道阿拉伯语,所以我可以告诉您,后者确实是前者的部分匹配项,因此,如果值实际上相反,则结果为true.如果您参考此阿拉伯字母表,则可以看到字母yā'(在表格底部)是有问题的相同字母.它的外观取决于它在单词中出现的位置.在前一个单词中,它出现在末尾,而在后者中,它是倒数第二个字母.

To clarify, العسكري is the pattern, and العسكرية is the input. Since I know Arabic I can tell you that the latter would indeed be a partial match of the former, so the result would be true if the values were actually reversed. If you refer to this table of Arabic alphabets, you can see that the letter yā’ (at the bottom of the table) is the same letter in question. Its appearance depends on where it occurs in a word. In the former word, it appears at the end, and in the latter it is the second-last letter.

当我从您的帖子中复制/粘贴时,这些值会颠倒过来,从而得出真实的值.为了更好地使用它,我们可以将单词分开以查看两种情况下的预期结果:

When I copy/paste from your post, the values get reversed, resulting in a true value. To work with this better, we can split the words apart to see the expected results in both scenarios:

string first = "العسكري";
string second = "العسكرية";
Console.WriteLine(Regex.IsMatch(first, second)); // false
Console.WriteLine(Regex.IsMatch(second, first)); // true

这篇关于为什么此正则表达式返回true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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