- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法使用 grep 进行重音不敏感搜索,最好保留 --color 选项?我的意思是 grep --secret-accent-insensitive-option aei
将匹配 àei,但也匹配 äēì 和 æi。
我知道我可以使用 iconv -t ASCII//TRANSLIT
从文本中删除重音符号,但我不知道如何使用它进行匹配,因为文本已转换(它适用于 grep -c 或 -l)
最佳答案
您正在寻找一大堆 POSIX 正则表达式 equivalence classes :
14.3.6.2 Equivalence Class Operators (
[= … =]
)Regex recognizes equivalence class expressions inside lists. A equivalence class expression is a set of collating elements which all belong to the same equivalence class. You form an equivalence class expression by putting a collating element between an open-equivalence-class operator and a close-equivalence-class operator.
[=
represents the open-equivalence-class operator and=]
represents the close-equivalence-class operator. For example, ifa
andA
were an equivalence class, then both[[=a=]]
and[[=A=]]
would match botha
andA
. If the collating element in an equivalence class expression isn’t part of an equivalence class, then the matcher considers the equivalence class expression to be a collating symbol.
$ echo "I match àei but also äēì and possibly æi" | grep '[[=a=]][[=e=]][[=i=]]'
I match àei but also äēì and possibly æi
^^^ ^^^
aei
这样的词.它不匹配的事实
æi
应该提醒您注意您正在使用的正则表达式库中存在的任何映射(大概是 gnulib,这是我链接和引用的内容),尽管我认为很可能是
digraphs即使是最好的等价类图也无法达到。
aei
的请求进入
[aei]
.
$ echo "I match àei but also äēì and possibly æi" | grep '[[=a=][=e=][=i=]]'
I match àei but also äēì and possibly æi
^ ^ ^^^ ^ ^^^ ^ ^ ^
grep -P
和大多数其他人使用的 perl 兼容正则表达式的 C 库)和
perl
支持后者但缺乏前者:
grep
使用 libpcre:失败
$ echo "I match àei but also äēì and possibly æi" \
| grep -P '[[=a=][=e=][=i=]](?<![aei])'
grep: POSIX collating elements are not supported
perl
本身:失败
$ echo "I match àei but also äēì and possibly æi" \
| perl -ne 'print if /[[=a=][=e=][=i=]](?<![aei])/'
POSIX syntax [= =] is reserved for future extensions in regex; marked by <-- HERE in m/[[=a=][=e= <-- HERE ][=i=]](?<![aei])/ at -e line 1.
python
(它有自己的 PCRE 实现):(静默)失败
$ echo "I match àei but also äēì and possibly æi" \
| python -c 'import re, sys;
print re.findall(r"[[=a=][=e=][=i=]]", sys.stdin.read())'
[]
python
,甚至
perl
不支持!这些没有太多。 (不要介意在第二个等价类上的提示,它仍然提示仅给出
/[[=a=]]/
。)这进一步证明了等价类是神秘的。
grep
最接近,因为它可以执行 BRE、ERE 和 PCRE,但不能将它们组合起来。
$ echo "I match àei but also äēì and possibly æi" \
| grep --color=always '[[=a=][=e=][=i=]]' \
| perl -pne "s/\e\[[0-9;]*m\e\[K(?i)([aei])/\$1/g"
I match àei but also äēì and possibly æi
^ ^^^
grep
强制颜色,以便 perl
可以键入颜色代码以注意匹配${GREP_COLOR:-01;31}
备注 grep
的颜色(默认使用相同的亮红色)perl
的 s///
命令匹配完整的颜色代码,然后匹配我们想要从最终结果中删除的非重音字母。它用(未着色的)字母 (?i)
之后的任何内容在 perl
正则表达式不区分大小写,因为 [[=i=]]
匹配 I
perl -p
在完成其 -e
后打印其输入的每一行执行 $GREP_COLORS
看起来像
ms=1;41
优先于较旧的
$GREP_COLOR
喜欢
1;41
.这更难提取(并且很难在两者之间切换),因此我在 try #4 中修改了 perl 代码以查找任何
SGR color code而不是只键入 grep 会添加的颜色。见
revision 2 of this answer对于之前的代码。
关于encoding - 如何做一个重音不敏感的grep?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20937864/
我使用术语“词法编码”是因为我没有更好的编码。 与字母相反,单词可以说是交流的基本单位。 Unicode 尝试为所有已知字母表的每个字母分配一个数值。对一种语言来说是字母,对另一种语言来说是字形。 U
我在UTF-8中有csv文件,我想将其保存在西里尔字母(Windows 1251)中...在中,我仅找到Atom -重新打开,并使用ctrl+shift+u编码 在 Sublime Text 3 中,
在lua 5.3引用手册中,我们可以看到: Lua is also encoding-agnostic; it makes no assumptions about the contents of a
看完后how gzip compression works它让我思考。如果源和代理服务器 (CDN) 都支持 gzip,则添加 Vary: Accept-Encoding头需要吗? 最佳答案 Vary
我正在向我的项目添加一项功能,我们将生成指向我们网站内部内容的链接,并且我们希望这些链接尽可能短,因此我们将制作自己的“URL 缩短器”。 我想知道生成的短网址的最佳编码/字母表是什么。这很大程度上是
我构建了一个用于压缩 HTTP 输出的模块。阅读spec ,我在以下几件事上没有发现明显的区别: 接受编码: 是否应将其视为与 Accept-Encoding: * 相同,还是视为不存在 header
在下面的代码中: package main import ( "bytes" "encoding/json" "fmt" ) type Student struct {
这个问题在这里已经有了答案: Why does encode delete the argument? (1 个回答) 6年前关闭。 Encode::encode 的文档说: encode $octe
在Android4.1中,实时编码应用中经常会请求关键帧。但是如何使用 MediaCodec 对象呢?当前的 Android4.2 SDK 似乎不支持它。 最佳答案 您可以 通过在排队输入缓冲区时指定
我有 CSV 格式的数据,这些数据在字符编码方面被严重打乱,可能在不同的软件应用程序(LibreOffice Calc、Microsoft、Excel、Google Refine、自定义 PHP/My
您可能知道,在 Perl 中,“utf8”意味着 Perl 对 UTF-8 的宽松理解,它允许使用技术上不是 UTF-8 中有效代码点的字符。相比之下,“UTF-8”(或“utf-8”)是 Perl
本文整理了Java中org.geotools.ysld.encode.YsldEncoder.encode()方法的一些代码示例,展示了YsldEncoder.encode()的具体用法。这些代码示例
现在还没有任何关于红色的书,因为它太新了。因此,我正在尝试遵循一本旧的 Rebol 书,并从中挽救我能得到的东西。 我发现一些命令,例如 read,由于文件编码的原因,我无法执行代码。 save %
错误:无法映射用于编码 UTF-8 的字符。由于版权特征,我收到此错误。我使用的是 Netbeans 7.2。 /** * � 2006 * * This class was generate
现在还没有任何关于红色的书,因为它太新了。因此,我正在尝试遵循一本旧的 Rebol 书,并从中挽救我能得到的东西。 我发现一些命令,例如 read,由于文件编码的原因,我无法执行代码。 save %
错误:无法映射用于编码 UTF-8 的字符。由于版权特征,我收到此错误。我使用的是 Netbeans 7.2。 /** * � 2006 * * This class was generate
我正在尝试使用客户端提供的值在 PHP 中测试 Soap Security header 。 他们提供的值(value)如... wTAmCL9tmg6KNpeAQOYubw== ...并说这是一个
这个问题已经有答案了: ClassNotFoundException/NoClassDefFoundError in my Java web application (3 个回答) 已关闭 8 年前。
世界!我正在使用 .Net Framework 4 System.Net.Sockets.TcpClient 编写简单的 HTML 服务器。 我在 StringBuilder html 中有 HTML
我正在尝试使用 Yii 来提供网络服务。自动生成的 wsdl 如下。我可以从命令行成功使用 Web 服务,但是通过 Web 浏览器,我得到了 SOAP-ERROR: Encoding: Violati
我是一名优秀的程序员,十分优秀!