473,508 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expression - looking to match 'www' only if it the start of a URL

string: www.google.com
"\\swww\\S*" returns " www.google.com'

string: http://www.google.com
"\\dwww\\d\\S*" matches, seems like it doesn't mind the http:// before
the www.

I want to match the string www.google.com, not http://www.google.com,
and I don't want the space that the first regular expression includes...

Nov 19 '05 #1
4 2093
use ^ at the start of your regular expression to say "from the start" ($ is
at the end...)

^www

if you want to ignore trailing/leading spaces, you'll either have to trim or
use explicit capture...^\s*(www)

or something like that...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ho********@yahoo.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
string: www.google.com
"\\swww\\S*" returns " www.google.com'

string: http://www.google.com
"\\dwww\\d\\S*" matches, seems like it doesn't mind the http:// before
the www.

I want to match the string www.google.com, not http://www.google.com,
and I don't want the space that the first regular expression includes...

Nov 19 '05 #2
Karl -
Thanks for your reply.
That seems to only work if www is the start of the string, not if it is
in the
middle of a string.

Karl Seguin wrote:
use ^ at the start of your regular expression to say "from the start" ($ is
at the end...)

^www

if you want to ignore trailing/leading spaces, you'll either have to trim or
use explicit capture...^\s*(www)

or something like that...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ho********@yahoo.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
string: www.google.com
"\\swww\\S*" returns " www.google.com'

string: http://www.google.com
"\\dwww\\d\\S*" matches, seems like it doesn't mind the http:// before
the www.

I want to match the string www.google.com, not http://www.google.com,
and I don't want the space that the first regular expression includes...


Nov 19 '05 #3
Not sure I know what you want then?

www proceeded by anything? by only certain things?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ho********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Karl -
Thanks for your reply.
That seems to only work if www is the start of the string, not if it is
in the
middle of a string.

Karl Seguin wrote:
use ^ at the start of your regular expression to say "from the start" ($
is
at the end...)

^www

if you want to ignore trailing/leading spaces, you'll either have to trim
or
use explicit capture...^\s*(www)

or something like that...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ho********@yahoo.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
> string: www.google.com
> "\\swww\\S*" returns " www.google.com'
>
> string: http://www.google.com
> "\\dwww\\d\\S*" matches, seems like it doesn't mind the http:// before
> the www.
>
> I want to match the string www.google.com, not http://www.google.com,
> and I don't want the space that the first regular expression
> includes...
>

Nov 19 '05 #4
Yes. I need to go through a paragraph of text and activate the links.
Some of them are good as they are - starting with http://. Others are
not - they start with www. So I need to find the www ones and add the
http:// before it. But I only want to do it if there is not already an
http:// before it.

Karl Seguin wrote:
Not sure I know what you want then?

www proceeded by anything? by only certain things?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ho********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Karl -
Thanks for your reply.
That seems to only work if www is the start of the string, not if it is
in the
middle of a string.

Karl Seguin wrote:
use ^ at the start of your regular expression to say "from the start" ($
is
at the end...)

^www

if you want to ignore trailing/leading spaces, you'll either have to trim
or
use explicit capture...^\s*(www)

or something like that...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ho********@yahoo.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
> string: www.google.com
> "\\swww\\S*" returns " www.google.com'
>
> string: http://www.google.com
> "\\dwww\\d\\S*" matches, seems like it doesn't mind the http:// before
> the www.
>
> I want to match the string www.google.com, not http://www.google.com,
> and I don't want the space that the first regular expression
> includes...
>


Nov 19 '05 #5

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

Similar topics

1
4155
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
2000
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing...
5
2486
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
11
5350
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
0
1011
by: hooterbite | last post by:
I need to loop through paragraphs of text and "activate" the links, which could either have the http:// or just start with www. I have no problem finding the ones that start with http://. The...
43
2764
by: Roger L. Cauvin | last post by:
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. "xyz123aaabbaabbbbababbbbaaabb" I'm...
3
2552
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
5129
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
7
4389
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
0
7114
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...
1
7034
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
7488
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
5623
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
4702
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...
0
3191
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...
0
1544
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 ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.