small parse problem
[1/5] from: anton::globalcenter::net::au at: 16-Sep-2000 21:48
Hi, I want to parse some input like this: www.somewhere.com&blah-blah OR www.somewhere.com-extrapathbit&blah-blah . How can I parse up to the hyphen (if it's there) making sure it's before the ampersand? The ampersand tells me it's the end of the url. So I don't want to parse all the way thru "blah". My two outputs should be, respectively: www.somewhere.com "" OR www.somewhere.com "extrapathbit" Please help! Anton.
[2/5] from: joel:neely:fedex at: 16-Sep-2000 9:42
Hi, Anton! I think this does what you want.
>> chopurl: func [s [string!] /local part1 part2 urlchopper] [
[ urlchopper: [ [ [ [ copy part1 to "-" skip copy part2 to "&" [ | [ copy part1 to "&" (part2: copy "") [ ] [ to end [ ] [ parse/all s urlchopper [ print [mold part1 mold part2] [ ]
>> chopurl "www.somewhere.com&blah-blah"
>> chopurl "www.somewhere.com-extrapathbit&blah-blah"
-jn- [anton--globalcenter--net--au] wrote:
[3/5] from: rryost:home at: 16-Sep-2000 10:50
Here's simple function that gets you part way: A console session follows:
>> u1: "www.somewhere.com&blah-blah"
>> u2: "www.somewhere.com-extrapathbit&blah-blah"
>> chpurl: func [s[string!]][
[ parse first parse s "&" "-"]
>> chpurl u1
>> chpurl u2
== ["www.somewhere.com" "extrapathbit"]
Outlook express has inserted underlines for the URL's above; ignore them. Also, the >> and [ above at the start of the lines are console session prompts. Russell [rryost--home--com] Russell [rryost--home--com]
[4/5] from: anton:globalcenter:au at: 17-Sep-2000 16:26
Joel, Sorry, I failed to mention that my input would also include more ampersands "&" after the first one (ie. at the end of subsequent urls). So rule one will always match, but it will include all of the url, the '&', a whole bunch of crap in between, and the next url up to its '&'....! You see the trouble? I need to match up to "-", but only 'non-ampersand' characters: non-ampersand: complement charset "&" I have had success using this in little parse expressions, but sticking it into my main parse expression has proved to be very difficult for me. Thanks for trying. :) Maybe today I'll figure it out. (Yet again, a solution to a parse problem that wasn't explained fully to start with... dear oh dear...;-) Anton. [joel--neely--fedex--com] wrote:
[5/5] from: rryost:home at: 17-Sep-2000 16:18
OK, I've extended the function in my last message to get a one-liner that yields the strings Joel wanted:
>> chpurl: func [url][foreach x parse first parse url "&" "-" [prin mold x
prin " "] print ""]
>> u1: "www.abc.com&blah-blah&stuff"
>> u2: "www.abc.com-extra&blah-blah"
>> chpurl u1
>> chpurl u2
www.abc.com "extra" Note the second & in u1 is ignored; 'first does that. The final 'print "" inserts a terminating line feed-carriage return. Russell [rryost--home--com]