regex - 如何联合 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.
解决方案
不要组合正则表达式。将 的一次调用的输出通过管道传输egrep
到 的另一次调用中egrep
。
egrep '\.$' ./lab1.txt | egrep '^\w+[aeiou]\b'
推荐阅读
- android - 在 Android 中使用 SVG 作为图像视图的资源
- javascript - 尝试使用条件对对象数组求和
- ios - 如何在 ReactJS 的 /apple-app-site-association 页面上提供 apple-app-site-association 文件
- json - 使用 Record<> 输入 JSON 数据并检查 key 是否存在
- python - 在不降低性能的情况下覆盖 __eq__ 和 __hash__
- c - 分段故障分叉和信号量
- sql - 感谢有关 SQL 中 CDC 方法的反馈
- list - Refactoring a list of map objects in Dart?
- spring-integration - 具有 void 方法返回类型的 Spring Integration Gateway:为什么不自动设置 NullChannel 回复通道?
- flutter - 如何创建动画确定循环进度指示器?