Sunday, March 18, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...