小编XPL*_*1ON的帖子

带有包含管道字符的正则表达式的 grep

我正在尝试使用包含管道字符的正则表达式进行 grep |。但是,它没有按预期工作。如下图所示,正则表达式与|inclusively不匹配。

在此处输入图片说明

这是我的 bash 命令

cat data | grep "{{flag\|[a-z|A-Z\s]+}}"

样本数据如下

| 155||NA||{{flag|Central African Republic}}||2.693||NA||0.000||0.000||0.019||0.271||0.281||0.057||2.066
|{{flagicon|Kosovo}} ''[[Kosovo]]'' <ref name="KOS" group=Note>{{Kosovo-note}}</ref>
|{{flagicon|Somaliland}} [[Somaliland|Somaliland region]]
|{{flagicon|Palestine}} ''[[Palestinian Territories]]''{{refn|See the following on statehood criteria:
Run Code Online (Sandbox Code Playgroud)

预期的输出是

| 155||NA||{{flag|Central African Republic}}||2.693||NA||0.000||0.000||0.019||0.271||0.281||0.057||2.066
Run Code Online (Sandbox Code Playgroud)

但是,使用Regex101.com对其进行测试,结果如预期。

linux bash grep regex command-line

3
推荐指数
1
解决办法
7408
查看次数

标签 统计

bash ×1

command-line ×1

grep ×1

linux ×1

regex ×1