Shengjie Shengjie - 1 year ago 132
Linux Question

sed - how to do regex groups using sed

Is there anyway you can do regex match group using sed like java regex pattern/match/group?

if i have string like


how do I use sed just to get the result like:


I am wondering does sed allow you to do something like java regex, you define the pattern like:


and then you can get the results as an array like:


Answer Source

You have to escape parentheses to group expressions:


And use them with \1, \2, etc.

EDIT: Also note just before SNAPSHOT that [.] will not match. Inside brackets . is literal. It should be [0-9.-]*

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download