perl non-greedy regex case matching too much
I have a file with something like
<post href="http://example.com/" description="Example website" tag="more
text"/>
What I want to get is Example website. Doing cat file | perl -pe
's/.*description=".*?"//' works as expected, and I get tag="more text"/>,
but when trying cat file | perl -pe 's/.*description="(.*)?"/\1/' I get
Example website" tag="more text/>, while I was expecting to get Example
website. So it seems there's something with the capturing and the
backreference that is not working as intended, and I'm not sure how to
solve it.
I could always do cat file | perl -pe 's/.*description="//;s/".*//', sure,
but I really want to understand how to solve it with the regular
expression, instead of doing two substitutions.
No comments:
Post a Comment