SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex problem with a href links

    Hi,

    I am having a problem with some Regex and i don't know how to fix. Take a look at the following code:

    PHP Code:
                if (Regex.IsMatch(input"<[aA].*xlink:href.*>.*</[Aa]>"))
                {
                    
    //Do something
                

    Now, there is other code with this conditional statement but it's not relevant as to what i am having problems with. This code checks for an a href link. I have 2 instances of links:

    <a title="Meet the Team" xlink:href="tcm:12-1451" xlink:title="Meet the Team">Meet the Team</a>
    <a title="Meet the Team" href="tcm:8-1451">Meet the Team</a>
    The top one works fine, but the bottom one does not because it doesn't have the "xlink" appended at the start. Does anyone know how i can change the regex so that it matches both?

    Many thanks,
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Not a guru of RE, someone lese can help you there, but why are you using XLink?
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I don't know if .NET uses Perl flavor regex, but if so try putting the "sometimes threre sometimes not" inside parentheses followed by a question mark (i.e. 0 or 1 occurences)

  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <[aA].*href.*>.*</[Aa]>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •