I want to grep the shortest match and the pattern should be something like:
<car ... model=BMW ...>
...
...
...
</car>
… means any character and the input is multiple lines.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re looking for a non-greedy (or lazy) match. To get a non-greedy match in regular expressions you need to use the modifier
?after the quantifier. For example you can change.*to.*?.By default
grepdoesn’t support non-greedy modifiers, but you can usegrep -Pto use the Perl syntax.