473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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)\$
Oct 16 '06 #1
5 1354
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.
Oct 16 '06 #2
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

Oct 16 '06 #3
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" <me*@NOSPAMunify.comwrote in message
news:ug**************@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.

Oct 16 '06 #4
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" <me*@NOSPAMunify.comwrote in message
news:ug**************@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.

Oct 16 '06 #5
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*comwrote in message
news:Oy**************@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)\$

Oct 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fazer | last post by:
Hello, I have a string which has a url (Begins with a http://) somewhere in it. I want to detect such a url and just spit out the url. Since I am very poor in regex, can someone show me how to...
75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
4
by: EagleRed | last post by:
have an ASP.NET web application on a virtual directory that is set to require SSL. After making the settings in IIS I try to debug from VS.NET and I get a message that the project is not configured...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
17
by: steve | last post by:
here's the deal...cvs, tick encapsulted data. trying to use regex's to validate records. here's an example row: 'AD,'BF','132465','06/09/2004','','BNSF','A','TYPE','1278','','BR','2999',''...
9
by: deko | last post by:
As I understand it, the characters that make up an Internet domain name can consist of only alpha-numeric characters and a hyphen (http://tools.ietf.org/html/rfc3696) So I'm trying to write...
5
by: Petra Meier | last post by:
Hello, I use the following script to parse URI and email: function parseLinks($sData){ $regexEmail = "/\w+((-\w+)|(\.\w+))*\@+((\.|-)+)*\.+/"; $sData = preg_replace($regexEmail, "<a...
1
by: al.moorthi | last post by:
the below program is working in Suse and not working on Cent 5: can any body have the solution ? #include <regex.h> #include <stdlib.h> #include <stdio.h> int main(){ char cool =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.