I want to read the clipboard, if it's an url do some stuff. Problem is url? doesn't do the job as:
url? to-url "any string" will return true
Is this normal ? How do I do the detection I want then ?
I want to read the clipboard, if it's an url do some stuff. Problem is url? doesn't do the job as:
url? to-url "any string" will return true
Is this normal ? How do I do the detection I want then ?
to-url makes a string into a REBOL datatype of URL!
What you want is to detect if a string conforms to the rules for a URL. That is nor easy or fool proof as many strings can be URLs in the real world, eg:
If you want to capture the more common cases (eg those that start with http://, https:// etc), then consider using parse.
This script almost does the job: link text
What it missing is some charset definitions (I think the code must have been hurriedly cut'n'pasted from somewhere else)....
alpha: charset [#"a" - #"z" #"A" - #"Z"]
digits: charset [#"0" - #"9"]
alphadigit: union alpha digits
...and an example of how to use it: Assuming you have saved it locally as uri.r:
url-parse: do %uri.r
parse "http://sss" parse-url/url
== true
parse "sss" parse-url/url
== false
You can use:
url? load "any://string"`
or
url? attempt [load "any string"]
To use REBOL's definition of a URL.