regex url validator?

Monte Goulding monte at appisle.net
Mon Oct 22 22:37:44 EDT 2018


Here’s one I have used which seems to work nicely:


constant kURLRegex = "^(?:(?:(([^:\/#\?]+:)?(?:(?:\/\/)(?:(?:(?:([^:@\/#\?]+)(?:\:([^:@\/#\?]*))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?"
	
local tOrigin, tScheme,  tUsername, tPassword, tHost, tNetloc, tPort, tPath, tParameters, tFragment

if not matchText(pURL, kURLRegex, tOrigin, tScheme, tUsername, tPassword, \
			tHost, tNetloc, tPort, tPath, tParameters, tFragment) then
	throw format("could not parse url '%s'", pURL)
end if


> On 23 Oct 2018, at 1:07 pm, Tom Glod via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hi peeps,
> 
> I'm trying to use regex to validate a list of URLs
> 
> I've tried 4 or 5 different "regular" expressions that supposedly work
> ..... but LC does not give me anything back.  None of them work,
> 
> Like for example ... this one.
> 
> ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$
> 
> or this one
> 
> /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
> 
> or this one just to make sure
> 
> (https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)
> 
> Does anyone know how to get these or others to work in LC?
> 
> Thanks,
> 
> Tom
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list