Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Regular Expression - looking to match 'www' only if it the start of a URL

Reply
Thread Tools

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

 
 
hooterbite@yahoo.com
Guest
Posts: n/a
 
      07-11-2005
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...

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      07-11-2005
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!)


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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...
>



 
Reply With Quote
 
 
 
 
hooterbite@yahoo.com
Guest
Posts: n/a
 
      07-11-2005
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!)
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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...
> >


 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      07-11-2005
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!)


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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!)
>>
>>
>> <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) 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...
>> >

>



 
Reply With Quote
 
hooterbite@yahoo.com
Guest
Posts: n/a
 
      07-12-2005
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!)
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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!)
> >>
> >>
> >> <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed) 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...
> >> >

> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Capture only first match in regular expression Mike Spencer Perl 0 04-19-2009 07:17 AM
Re: Capture only first match in regular expression Peter Tuente Perl 0 04-17-2009 11:36 AM
Re: Capture only first match in regular expression Jürgen Exner Perl 0 04-12-2009 02:40 AM
Regular expression to match only strings NOT containing particular words Dylan Nicholson Perl Misc 6 10-19-2007 02:33 PM
Regular Expression - looking to match 'www' only if it is the start of a URL hooterbite@yahoo.com ASP .Net 0 07-20-2005 04:11 PM



Advertisments