当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - Why does grep return nothing?

问题描述:

I'm somewhat at ease with regex, but not with grep particularly, and can't figure out why the following regex returns nothing:

wget -qO- 'http://www.acme.com/index.html' | grep -iPo '(?s)(^<div class="titlebar">.+?<div class="colleft">)'

I prepended (?s) because the catch-all ".+?" includes carriage-returns (either CRLF, CR, or LF, depending on how the text was saved).

Any idea why it doesn't work as expected?

Thank you.

网友答案:

grep is line-oriented, so if there are newlines between the tags, grep can't find it. You'll want:

wget -qO- 'http://website.invalid/index.html' |
perl -0777 -nE 'say for /(^<div class="titlebar">.+?<div class="colleft">)/msg'
分享给朋友:
您可能感兴趣的文章:
随机阅读: