Making regex work...
Posted
#1
(In Topic #1374)
Regular

( string is a suggested URL match! ?)
Thanks,
C.
Posted
Guru

you have to use 2 backslashes \ for each regex specific escape.
2 backslashes \ in gambas is \ so for example \/ that you may use in regex but not gambas has to be input as \/
Also all the other chars like \w will have to be \w , \$ \+ and so on.
Posted
Regular

Interpreter is happy with the expression string now all '\' are '\'
But am getting this error in the Regexp.Match line of code:-
Will try other suggested (online) web URL-match expressions, but any from the forum gratefully received.
Thanks,
C.
Posted
Guru

I'd use something simpler like Like
If webURL Like "{http,https,ftp}://*" Then
Although I don't really know what exactly you are checking for.
Posted
Regular

I needed a view and URL textbox that the user could enter or paste the URL of a webpage/download. Also wanted the input value to be compliant with URI syntax before the web request is submitted to the webView.url property.
After a few attempts, along with Bruce's help with string escape characters, I came up with the following code:-
The Regex match-string used here was the most reliable - and error-free - that I could find online. (scoured stackoverflow.com,
but there are many other sites with ideas for 'best' URI Regex - note: some raise errors, so maybe use Try command!).
Code (gambas)
- webUrl = metaWebURL.text
- regexA =
- "(([\\w]+:)?//)?(([\\d\\w]|%[a-fA-f\\d]\{2,2})+(:([\\d\\w]|%[a-fA-f\\d]\{2,2})+)?@)?([\\d\\w][-\\d\\w]\{0,253}[\\d\\w]\\.)+[\\w]\{2,63}(:[\\d]+)?(/([-+_~.\\d\\w]|%[a-fA-f\\d]\{2,2})*)*(\\?(&?([-+_~.\\d\\w]|%[a-fA-f\\d]\{2,2})=?)*)?(#([-+_~.\\d\\w]|%[a-fA-f\\d]\{2,2})*)?"
- metaWebURL.text = webUrl & " is downloading, please wait..."
- WebView1.Url = webUrl
- metaWebURL.text = webUrl & " is not URI compliant"
Hope this helpful to folk.
C.
1 guest and 0 members have just viewed this.




