- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我有这个正则表达式:
[ ]{1}[^\w]*(шесть)[^\w]*[ ]{1}
及其变体:
[ ]{1}[^\w]*(conservation)[^\w]*[ ]{1}
我使用这个文本,here , 对其进行测试:
"""Наверное, по одному на пару отделений, а их больше десяти. Интересно, каждый работает по шесть часов в неделю? Работать, очевидно, некому, раз принимают сами заведующие. Но неужели экономия на нескольких диагностах"""
"""Following the assassination of President McKinley in September 1901, Roosevelt, at age 42, became the youngest United States President in history. Leading his party and country into the Progressive Era, he championed his "Square Deal" domestic policies, promising the average citizen fairness, breaking of trusts, regulation of railroads, and pure food and drugs. Making conservation a top priority, he established myriad new шесть national parks, forests, and monuments intended to preserve the nation's natural resources. In foreign policy, he focused on Central America, where he began construction of the Panama Canal. He greatly expanded the United States Navy, and sent the Great White Fleet on a world tour to project the United States' naval power around the globe. His successful efforts to end the Russo-Japanese War won him the 1906 Nobel Peace Prize."""
两者都是我发现的随机文本。但这不是重点。
当使用第一个正则表达式时,我得到以下匹配项:
по одному на пару отделений, а их больше десяти. Интересно, каждый работает по шесть часов в неделю? Работать, очевидно, некому, раз принимают сами заведующие. Но неужели экономия на нескольких
这是第一个文本 block ,俄文 block 。
在第二个中,它只匹配
шесть
匹配的上下文是
... new шесть national parks ...
如果我使用英文单词,比如“conservation”,它只会匹配英文文本 block 中的单词。
如果我将它添加到俄语文本中,类似于:
... шесть conservation часов ...
它匹配相同的大块文本,如“шесть”。
为什么会这样?是因为文字是俄语吗?
我不是百分百确定这个正则表达式的作用,但在英文文本中它会找到括号中的单词。我假设它对其他语言也是如此。
这并不重要,但仅供引用,我在 Python 2.7 中使用 re2 库。但是,由于我在网上得到了相同的结果,我假设它要么是我不理解的正则表达式,要么是非英语文本的问题。
谢谢!
编辑 1:
代码:
source = the_text_above
term = "шесть"
expression = regex_builder(term) # This returns the regex I posted
compiled_pattern = re2.compile(expression, re2.IGNORECASE, re2.U) # This raises an error: RegexError: pattern too large - compile failed
compiled_pattern.search(source).span() # This returns the start and end of the chunk of text I mentioned.
编辑 1 的附录:当我不使用 re2.U 时返回文本 block
编辑 2:
我也尝试过:
compiled_pattern = re.compile(expression, re.U)
我得到了相同的结果。
编辑 3 - 已解决:
因此,我尝试使用 re2.IGNORECASE 和 re2.U 标志再次编译并且成功了。
现在我的代码是这样的:
source = the_text_above
term = "шесть"
expression = regex_builder(term)
compiled_pattern = re2.compile(expression, re2.IGNORECASE | re2.U)
compiled_pattern.search(source).span()
它是这样工作的。
最佳答案
在 RE2 中,如果不指定 re2.U
标志,\w
仅匹配 ASCII 字母:
\w
word characters (≡[0-9A-Za-z_]
)
因此 [^\w]
匹配西里尔字母。
因此,您需要使用 re2.U
标志。
由于您将 re2.I
与 re2.U
组合在一起,因此您需要在两者之间使用按位或 (|
):
re2.compile(<YOUR_PATTERN>, re2.I | re2.U)
关于python - 正则表达式为英语和俄语提供不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34632702/
我必须设计一个俄语版的网站。我从翻译那里得到文本。我把它复制到 Dreamweaver 的代码中,但它不起作用。 我有平常的脑袋: 我该怎么办? 最佳答案 您应该将文件的编码更改为 UTF-8。您可
我正在使用 google-api-spelling-java jar 库。而且我需要使用更多的语言来使用,其中之一就是俄语。我在哪里可以获得相同的库但具有更多语言? 最佳答案 您可以在此处下载源代码并
我有一张表,用于存储一些文本标签。最初它是使用 latin_swedish_ci(默认)排序规则构建的。 现在我需要支持其他语言,例如俄语。我有两个使用这些标签的页面。一个显示它们很好,尽管该表仍然使
尝试匹配字符串“Манихина Галина Владимировна”和其他相同格式的字符串。也就是三个字的专有名词。我是正则表达式的新手,不确定我的陈述有什么问题。 import java.ut
我应该使用哪种排序规则将阿拉伯语、俄语、英语和德语字符保存到数据库中? 我的列设置是nvarchar(100) 我目前已将其设置为: SQL_Latin1_General_Cp1256_CI_AS 它
我有一个覆盖了 onKeyDown() 的自定义 View 。当我使用标准的 Android 英语(或意大利语)软键盘时它工作正常,但是当我将设备设置为俄语时,按键事件永远不会到达 onKeyDown
也许有人知道从中检索翻译的最佳方式是什么。是否有用于阅读 Multitran 词典数据库的图书馆?我的目标是一个简单的程序,它将检索给定的俄语单词的英文翻译。 最佳答案 也许你可以使用 StarDic
我尝试使用提要解析器阅读 RSS 提要。 import feedparser url = 'http://example.com/news.xml' d=feedparser.parse(url) f
我正在尝试通过 setlocale 使用俄语: setlocale(LC_TIME,"ru_RUS.utf8"); echo strftime("%A, %B %d", time()); 输出是:8
我在数据库中有一个具有俄罗斯值(value)观的项目。我需要做的就是附和他们,但事实证明这比预期的要困难。所有俄语字符都只是作为问号打印。 IE: ??? ? ????????对于我尝试过的每种编码,
我已经花了几天时间,我做错了什么?我就是不能把俄语字符弄出来。尝试了上面的所有代码 - 它没有帮助。下面我用不同的选项引用我的代码。请帮帮我。 库连接如下 dependencies { imp
我正在我的 Android 设备(Motorola Defy,2.1)上调试应用程序,该应用程序从网络获取俄语 HTML 页面,但无法显示它。它显示为 link text 。HTML 页面采用 UTF
过去几个小时我一直对俄语制表符分隔的 txt 文件感到困惑。其外观如下: CODE AD_GROUP KEYWORD MATCH_TYPE 009966 Автостраховка
我需要在基于 Spring 的项目中为俄语和葡萄牙语等语言本地化一组 JSP 页面。 我尝试的是,使用 EL 和 JSTL。但是它们都不支持上述语言。 (显示迷失方向的字符符号) JSP 片段(用于
我对我的英语感到抱歉。我正在尝试使用 PdfPTable(iText 库)创建表。表格显示空列![在此处输入图像描述][1] public class CreatePDF { File file; B
我正在尝试在包含非拉丁字符的 Qt/C++ 软件上加载文件。一个使用俄语文件名的用户报告的问题,我试图用下面的代码快速修复它。 示例文件名是(我不会读或写俄语!):Летний сад.dgr boo
是否可以在 javascript 的正则表达式中使用俄语字符? 也许使用\p{Cyrillic}? 如果是,请提供一个基本的用法示例。 例子: var str1 = "абв прв фву"; va
2016 年 31 日 15:10 декабря不是英语。 декабря = 十二月 DateTime.Parse("31/December/2016").ToString("yyyymmdd")
当我将数据添加到工作簿时,需要将公式从较早的单元格复制到新单元格。 我使用以下公式来计算我的增长率: =WENN(ODER(K9="";L9="");"";WENNFEHLER((L9-K9)/K9;
如题,我不知道如何在C中解析包含字母字符和来自其他语言的特殊字符的字符串。谁能帮助我如何在C中区分它们?。我是否需要安装一些可选组件来帮助C接受字符?(我在linux环境中)。非常感谢您的回复。 最佳
我是一名优秀的程序员,十分优秀!