开发者

Can any one help me out in creating a regular expression

开发者 https://www.devze.com 2023-03-08 22:45 出处:网络
I want to validate these type of URls http://anyword.anyword.anyword/anyword/anyword/download.aspx?anyword=http://www.anyword.anyword/anyword/anyword/anyword/ab-cd.cab

I want to validate these type of URls

http://anyword.anyword.anyword/anyword/anyword/download.aspx?anyword=http://www.anyword.anyword/anyword/anyword/anyword/ab-cd.cab

anyword could be anything(only st开发者_高级运维rings though) but i need to have .cab at the end

Ex:

http://stack.meta.com/default/cabs/newpage.aspx?mylink=http://www.stack.com/pages/sections/articles/en-ia.cab

Thanks in advance!!!!


Use below

For .cab at last

^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(cab)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$

For all

^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$


http://[\s\S]{1,200}(?=.cab)

If you're using a single link (not searching from many links) then this might suffice. You can easily modify and test this regex @ http://gskinner.com/RegExr/.

I'm still a beginner @ regex construction so forgive me if it doesn't work the way you need.


you can use http://www.regexlib.com site for making your regular expression validation.....

this is the best site where all best validation expressions available and lots of


To match that it is ending with .cab you can use:

\.cab$

notice the $ that is the important point defining the end of your string.

The other part depends on how deep you want to validate your link. A simple check would be

^http.*\.cab$

that would allow everything that starts with http and ends with .cab

For more sophisticated URL checks you can search here on SO. see e.g. this questions/4538212/regular-expression-to-validate-the-url. This has been discussed here many times.


Try

^http:\/\/((\w+\.?)+\/?){1,4}\.aspx\?\w+\=http:\/\/((\w+\.?)+\/){1,4}[a-z]{2}-[a-z]{2}\.cab$

Though I believe your question lacks requirements... :)


IMP, this maybe match it. "\\.cab" It needs 2 "\". Hope help you!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号