469,958 Members | 1,904 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,958 developers. It's quick & easy.

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 1977
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bradley Plett | last post: by
11 posts views Thread by Dimitris Georgakopuolos | last post: by
43 posts views Thread by Roger L. Cauvin | last post: by
3 posts views Thread by Zach | last post: by
25 posts views Thread by Mike | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.