Non greedy pattern match in sed
abate at discus.anu.edu.au
Tue Aug 13 19:09:38 EST 2002
On Tue, Aug 13, 2002 at 04:25:55PM +1000, Michael Still wrote:
> I would like non greedy regexp matching in sed.
> echo "/* This is a */ test /* line */" | sed 's/\/\*.*\*\//g'
> Non greedy toggle
I hope I'm not going to say something really stupid... but this seams to
me the same reason why you can't parse html with sed...
however if you avoid the .* part of the expression (that is the greedy
part) you can write something like that ... sed 's/\/\*[a-z A-Z]*\*\///g'
but you can't have nested comments.
To parse this line you need something more sophisticated than sed to
take care of the possibly nesting comments (like perl...)
I guess I've not really answered to your question...
More information about the linux