tags:

views:

29

answers:

2

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 ?

+2  A: 

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
Sunanda
Great answer, thanks a lot.
Rebol Tutorial
+1  A: 

You can use:

url? load "any://string"`

or

url? attempt [load "any string"]

To use REBOL's definition of a URL.

ChrisRG
Seems great, will try thank you.
Rebol Tutorial