Sunday, 18 March 2018

regex - How to make sed do non-greedy match?

I cannot seem to figure out how to come up with the correct regex for my bash command line.
Here's what I am doing:




echo "XML-Xerces-2.7.0-0.tar.gz" | sed -e's/^\(.*\)-[0-9].*/\1/g'


This gives me the output of ...



XML-Xerces-2.7.0


... but want I need is the output to be ...




XML-Xerces


... I guess I could do this ...



 echo "XML-Xerces-2.7.0-0.tar.gz" | sed -e's/^\(.*\)-[0-9].*/\1/g' | sed -e's/^\(.*\)-[0-9].*/\1/g'


... but I would like to know how understand sed regex a little better.




Update:



I tried this ...



echo "XML-Xerces-2.7.0-0.tar.gz" | sed -e's/^\([^-]*\)-[0-9].*/\1/g'


... as suggest but that outputs XML-Xerces-2.7.0-0.tar.gz

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...