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.
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.
To get a non-greedy match in regular expressions you need to use the non-greedy modifier ?
after the quantifier, for example : .*?
.
<car[^>]* model=BMW [^>]*>.*?</car>
You will also need the dot all modifier so that the dot matches new lines.
However it looks suspiciously like you are trying to use regular expressions to parse XML. If your document is in fact XML then you should avoid using regular expressions to do this and instead use an XML parser. If you state what language you are using I can point you towards an appropriate library for that language.