Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Simple Regex to Require start with http:// or https:// (http://www.velocityreviews.com/forums/t380869-simple-regex-to-require-start-with-http-or-https.html)

Phillip Vong 10-16-2006 09:16 PM

Simple Regex to Require start with http:// or https://
 
Can someone help me write a simple regex that require a textbox start with
http:// or https:// ?

I don't know how to write regex. I usually rely on http://regexlib.com but
I couldn't find anything good. The closest one I found was this one, but it
requires a www also and not all my sites have www. Thanks in advance.

^(ht|f)tp((?<=http)s)?://((?<=http://)www|(?<=https://)www|(?<=ftp://)ftp)\.(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(co|me|org|ltd|plc|net|sch|ac|mod|nhs|police|g ov)\$



Mark E. Hansen 10-16-2006 09:39 PM

Re: Simple Regex to Require start with http:// or https://
 
On 10/16/06 14:16, Phillip Vong wrote:
> Can someone help me write a simple regex that require a textbox start with
> http:// or https:// ?
>
> I don't know how to write regex. I usually rely on http://regexlib.com but
> I couldn't find anything good. The closest one I found was this one, but it
> requires a www also and not all my sites have www. Thanks in advance.
>
> ^(ht|f)tp((?<=http)s)?://((?<=http://)www|(?<=https://)www|(?<=ftp://)ftp)\.(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(co|me|org|ltd|plc|net|sch|ac|mod|nhs|police|g ov)\$
>
>


Well, if that string requires that the text begin with what you want, followed
by other stuff, can't you just remove the other stuff?

If you look at the beginning of that string:

^(ht|f)tp((?<=http)s)?://

That says that the value must be one of the following:

http://
https://
ftp://

Isn't that what you want? If you really don't want the "ftp://", you can
change it to remove the ftp junk, but I would just use it the way it is.

apathetic 10-16-2006 09:47 PM

Re: Simple Regex to Require start with http:// or https://
 
Phillip Vong wrote:
> Can someone help me write a simple regex that require a textbox start with
> http:// or https://


All you need is:

^https?://

Where the special characters are:

^ = start of string
? = optional character

Regards,
apathetic


Phillip Vong 10-16-2006 09:49 PM

Re: Simple Regex to Require start with http:// or https://
 
Mark, thanks for the quick reply. I stuck
^(ht|f)tp((?<=http)s)?://

In the Regular Expression validator and it didn't work. Even if I start the
text box with http:// or https://, it still triggers the validator and I get
the error message.




"Mark E. Hansen" <meh@NOSPAMunify.com> wrote in message
news:ugIiGuW8GHA.3280@TK2MSFTNGP02.phx.gbl...
> On 10/16/06 14:16, Phillip Vong wrote:
>> Can someone help me write a simple regex that require a textbox start
>> with
>> http:// or https:// ?
>>
>> I don't know how to write regex. I usually rely on http://regexlib.com
>> but
>> I couldn't find anything good. The closest one I found was this one, but
>> it
>> requires a www also and not all my sites have www. Thanks in advance.
>>
>> ^(ht|f)tp((?<=http)s)?://((?<=http://)www|(?<=https://)www|(?<=ftp://)ftp)\.(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(co|me|org|ltd|plc|net|sch|ac|mod|nhs|police|g ov)\$
>>
>>

>
> Well, if that string requires that the text begin with what you want,
> followed
> by other stuff, can't you just remove the other stuff?
>
> If you look at the beginning of that string:
>
> ^(ht|f)tp((?<=http)s)?://
>
> That says that the value must be one of the following:
>
> http://
> https://
> ftp://
>
> Isn't that what you want? If you really don't want the "ftp://", you can
> change it to remove the ftp junk, but I would just use it the way it is.




Mark E. Hansen 10-16-2006 09:54 PM

Re: Simple Regex to Require start with http:// or https://
 
On 10/16/06 14:49, Phillip Vong wrote:
> Mark, thanks for the quick reply. I stuck
> ^(ht|f)tp((?<=http)s)?://
>
> In the Regular Expression validator and it didn't work. Even if I start the
> text box with http:// or https://, it still triggers the validator and I get
> the error message.


But using the longer expression works?

I don't understand, then. Sorry.

>
>
>
>
> "Mark E. Hansen" <meh@NOSPAMunify.com> wrote in message
> news:ugIiGuW8GHA.3280@TK2MSFTNGP02.phx.gbl...
>> On 10/16/06 14:16, Phillip Vong wrote:
>>> Can someone help me write a simple regex that require a textbox start
>>> with
>>> http:// or https:// ?
>>>
>>> I don't know how to write regex. I usually rely on http://regexlib.com
>>> but
>>> I couldn't find anything good. The closest one I found was this one, but
>>> it
>>> requires a www also and not all my sites have www. Thanks in advance.
>>>
>>> ^(ht|f)tp((?<=http)s)?://((?<=http://)www|(?<=https://)www|(?<=ftp://)ftp)\.(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(co|me|org|ltd|plc|net|sch|ac|mod|nhs|police|g ov)\$
>>>
>>>

>>
>> Well, if that string requires that the text begin with what you want,
>> followed
>> by other stuff, can't you just remove the other stuff?
>>
>> If you look at the beginning of that string:
>>
>> ^(ht|f)tp((?<=http)s)?://
>>
>> That says that the value must be one of the following:
>>
>> http://
>> https://
>> ftp://
>>
>> Isn't that what you want? If you really don't want the "ftp://", you can
>> change it to remove the ftp junk, but I would just use it the way it is.

>
>


Cowboy \(Gregory A. Beamer\) 10-17-2006 12:28 AM

Re: Simple Regex to Require start with http:// or https://
 
You can option out the www and make it domain name straight or some other
word. But, that would open things up to where you might as well do something
like replace the wwww with

\w{1,5}

or somehting similar (alpha between 1 and 5 chars long). You can also do
something like \w+ etc. to state you do not know how long.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Phillip Vong" <phillip_vong*at*yahoo*dot*com> wrote in message
news:Oyr3shW8GHA.1492@TK2MSFTNGP02.phx.gbl...
> Can someone help me write a simple regex that require a textbox start with
> http:// or https:// ?
>
> I don't know how to write regex. I usually rely on http://regexlib.com
> but I couldn't find anything good. The closest one I found was this one,
> but it requires a www also and not all my sites have www. Thanks in
> advance.
>
> ^(ht|f)tp((?<=http)s)?://((?<=http://)www|(?<=https://)www|(?<=ftp://)ftp)\.(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(co|me|org|ltd|plc|net|sch|ac|mod|nhs|police|g ov)\$
>





All times are GMT. The time now is 12:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.