Regex 具有前瞻模式的grep命令不选择任何内容

Regex 具有前瞻模式的grep命令不选择任何内容,regex,awk,grep,Regex,Awk,Grep,我试图使用以下grep命令: grep '(.*)(?=(png|html|jpg|js|css)(?:\s*))(png|html|jpg|js|css.*\s)' file 文件包含以下内容: http://manage.bostonglobe.com/GiftTheGlobe/LandingPage.html https://manage.bostonglobe.com/cs/mc/login.aspx?p1=BGFooter https://www.bostonglobe.com

我试图使用以下grep命令:

grep '(.*)(?=(png|html|jpg|js|css)(?:\s*))(png|html|jpg|js|css.*\s)' file
文件包含以下内容:

 http://manage.bostonglobe.com/GiftTheGlobe/LandingPage.html
 https://manage.bostonglobe.com/cs/mc/login.aspx?p1=BGFooter
 https://www.bostonglobe.com/bgcs
 /newsletters?p1=BGFooter_Newsletters
 https://bostonglobe.custhelp.com/app/home?p1=BGFooter
 https://bostonglobe.custhelp.com/app/answers/list?p1=BGFooter
 /tools/help/stafflist?p1=BGFooter
 https://www.bostonglobemedia.com/
 https://manage.bostonglobe.com/Order/newspaper/Newspaper.aspx
 https://www.facebook.com/globe
 https://twitter.com/#!/BostonGlobe
 https://plus.google.com/108227564341535363126/about
 https://epaper.bostonglobe.com/launch.aspx?pbid=2c60291d-c20c-4780-9829-     b3d9a12687cf
 http://nieonline.com/bostonglobe/
 https://secure.pqarchiver.com/boston-sub/no_default.html?ss=1&url=%2Fboston-sub%2Fadvancedsearch.html
 /tools/help/privacy?p1=BGFooter
 /tools/help/terms-service?p1=BGFooter
 /termsofpurchase?p1=BGFooter
 https://www.bostonglobemedia.com/careers
 /css/globe-print.css?v=19256I1935
 //meter.bostonglobe.com/css/style.css
 /css/globe-print.css?v=19256I1935
 //cdn.blueconic.net/bostonglobemedia.js
 /js/lib/rwd-images.js,lib/respond.min.js,lib/modernizr.custom.min.js,globe-          define.js,globe-controller.js?v=19256I1935
 data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==
 /js/lib/jquery.js,lib/lo-dash-custom-2.4.1.js,lib/a9.js,lib/pb.js,dist/ad-     init.js,globe-newsletter.js,globe-profile-page.js,dist/globe-topic-nav.js,dist/rakuten.js?v=19256I1935
 //dc8xl0ndzn2cb.cloudfront.net/js/bostonglobe/v0/keywee.min.js

由于某些原因,它没有从该文件中选择任何内容,我尝试了不同的标志,但似乎无法找出错误所在

您正在使用一个带有POSIX BRE引擎的PCRE正则表达式,该引擎是默认的
grep
引擎

要使这些模式正常工作,您应该使用
-p
选项(在GNU
grep
中提供):

为了开发和测试PCRE模式,通常建议使用一种众所周知的方法


请注意,在Mac OS上,您可以。

您是否尝试过
-p
标志?顺便问一下,匹配的规则是什么?这种模式似乎一团糟。实际上,您使用的是带有POSIX BRE(默认)引擎的PCRE正则表达式,这显然是一个错误。Lookahead需要
-P
开关,但您可以使用
grep-E'(.*)(png | html | jpg | js | css.*\s)文件删除它
@Igor Kamalov,请在您的问题中添加预期的输出(由于您添加了不同的标签,我们可以尝试看看我们是否可以在其他方面给出答案)。-P flag worked guys感谢您的EGEX101通常不是但强烈推荐的工具,因为它是唯一支持使用PCRE特殊序列并为其提供调试工具的在线regex测试器。
grep -P 'YOUR_PCRE_PATTERN'
     ^^