473,800 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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((?<=h ttp)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|pol ice|gov)\$
Oct 16 '06 #1
5 1369
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((?<=h ttp)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|pol ice|gov)\$

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((?<=h ttp)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((?<=h ttp)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*@NOSPAMunif y.comwrote in message
news:ug******** ******@TK2MSFTN GP02.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|pol ice|gov)\$


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((?<=h ttp)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((?<=h ttp)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*@NOSPAMunif y.comwrote in message
news:ug******** ******@TK2MSFTN GP02.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|pol ice|gov)\$


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((?<=h ttp)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*a t*yahoo*dot*com wrote in message
news:Oy******** ******@TK2MSFTN GP02.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((?<=h ttp)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|pol ice|gov)\$

Oct 17 '06 #6

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

Similar topics

4
1889
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 do it using a few examples? Thanks a lot!
75
4673
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 functions are simplified versions of the full featured methods for compiled regular expressions. Most non-trivial applications always use the compiled form UNQUOTE
4
9773
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 numeric value according to an arbitrary regular expression.
4
1907
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 to debug. However, the project has all the settings and I can debug it if I remove the SSL requirement. How can I debug a project that where the virtual directory is set to require SSL
18
3044
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
1657
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','' ,'LX','','01','09','1','','','','','','','','','CUSTOM JOB CODE TEST' record type is in the 8th column ('1278'). using regex b/c there are a miriad of types that cause other data w/n the record (or related records) to be in/valid. i'm having problems...
9
30482
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 regex that will provide a basic url format validation: starts with http or https (the only 2 prots I'm interested in), is followed by '://', then ( followed by a '.' appearing 1 or more times), then followed by anything *, and is case-insensitive.
5
426
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 id='external' href='mailto:'$0'>$0</a>", $sData); $regexURI = '#(^|{1})(http://|ftp://|https://|news:)(+) (|$)#sm';
1
5624
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 = "http://www.cnn.com:80/wowsers.html";
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.