|
From: | Peter O'Gorman |
Subject: | Re: [PATCH] Use expr where possible |
Date: | Wed, 15 Jun 2005 22:36:41 +0900 |
User-agent: | Mozilla Thunderbird 1.0 (Macintosh/20041206) |
Peter O'Gorman wrote:
Paul Eggert wrote:"Peter O'Gorman" <address@hidden> writes:% expr "Xpowerpc-apple-darwin8.1.0" : 'X[^--]*-[^--]*-\(.*\)'How about the following instead? I'd rather use a simpler regexp if it works. Can you please verify that this works on the broken implementation? Thanks. $ expr 'Xpowerpc-apple-darwin8.1.0' : '.*-\(.*\)' darwin8.1.0 $ expr 'Xpowerpc-apple-darwin8.1.0' : '.*-\(.*\)-.*' apple $ expr 'Xpowerpc-apple-darwin8.1.0' : 'X\(.*\)-.*-' powerpcYes, this works also. Thank you.
To reply to myself, Bill Fenner just mentioned on irc that this will give a bad result for "i686-pc-linux-gnu" he instead suggests using [.-.] as in:
expr "Xpowerpc-apple-darwin8.1.0" : 'X[^.-.]*-[^.-.]*-\(.*\)' expr "Xpowerpc-apple-darwin8.1.0" : 'X[^.-.]*-\([^.-.]*\)-.*' expr "Xpowerpc-apple-darwin8.1.0" : 'X\([^.-.]*\)-.*-.*' irc paste, sorry 22:29 < fenestro> although if you want all 3 parts, using set and echo | sed is probably less processes (if expr isn't builtin) 22:30 < fenestro> set `echo foo-bar-baz-boo | sed -e 's/\([^-]*\)-\([^-]*\)-\(.*\)/$1 $2 $3/' 22:30 < fenestro> a=$1 22:30 < fenestro> b=$2 22:30 < fenestro> c=$3 Or simply reverting and using echo | sed... (I prefer this solution) Peter -- Peter O'Gorman - http://www.pogma.com
[Prev in Thread] | Current Thread | [Next in Thread] |