首页 > 解决方案 > 如何联合 2 正则表达式?

问题描述

我有两个正则表达式:

1) egrep \\.$./lab1.txt - 返回以点结尾的行

2) egrep '^\w+[aeiou]\b'./lab1.txt - 返回第一个单词以元音结尾的行

我需要加入这个表达式。所以,我需要返回一个以点结尾的行并且第一个单词以元音结尾。我怎样才能做到这一点?

我的演示 txt 文件(lab1.txt):

Hello world
Hello world.
London is the capital of GB.
Oslo is the capital of Norway
Oslo is the capital of Norway.

所以,最终的表达式应该返回:

Hello world.
Oslo is the capital of Norway.

标签: regexgrep

解决方案


不要组合正则表达式。将 的一次调用的输出通过管道传输egrep到 的另一次调用中egrep

egrep '\.$' ./lab1.txt | egrep '^\w+[aeiou]\b'

推荐阅读