|
|
|
|
|
by draegtun
4665 days ago
|
|
Have a look at Rebol parse dialect for an alternative mind blowing way of doing things! Here's is OP example ported to parse: ; build some sub rules
r: context [
domain: charset [#"a" - #"z" #"-"]
proto: ["http" | "https"]
tld: ["com" | "org"]
]
; simple URI rule
rule: [
copy proto r/proto
"://"
some [copy d some r/domain #"." (append domain d)]
copy tld r/tld
["/" | end]
]
; capture
proto: tld: d: none
domain: []
; usage example
parse "http://www.example.com/" rule
; Above returns true with following variables set to...
;
; proto = "http"
; domain = ["www" "example"]
; tld = "com"
Here's a nice tutorial on parse (though it's probably Rebol 2 centric) - http://www.codeconscious.com/rebol/parse-tutorial.html |
|