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

Discussion in 'ASP .Net' started by hooterbite@yahoo.com, Jul 11, 2005.

  1. Guest

    , Jul 11, 2005
    #1
    1. Advertising

  2. Karl Seguin Guest

    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!)


    <> wrote in message
    news:...
    > 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...
    >
     
    Karl Seguin, Jul 11, 2005
    #2
    1. Advertising

  3. Guest

    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!)
    >
    >
    > <> wrote in message
    > news:...
    > > 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...
    > >
     
    , Jul 11, 2005
    #3
  4. Karl Seguin Guest

    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!)


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

    >
     
    Karl Seguin, Jul 12, 2005
    #4
  5. Guest

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

    > >
     
    , Jul 12, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    365
  2. Jürgen Exner
    Replies:
    0
    Views:
    2,748
    Jürgen Exner
    Apr 12, 2009
  3. Peter Tuente
    Replies:
    0
    Views:
    16,916
    Peter Tuente
    Apr 17, 2009
  4. Mike Spencer
    Replies:
    0
    Views:
    2,960
    Mike Spencer
    Apr 19, 2009
  5. Dylan Nicholson
    Replies:
    6
    Views:
    377
    A. Sinan Unur
    Oct 19, 2007
Loading...

Share This Page