Regex.Replace not working as required.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    Regex.Replace not working as required.

    Hi there,



    I am trying to replace text in my xsl file. I have to replace all the http and https. But I can leave any links that start with <a href>

    Ie; http://www.google.com has to replaced. But < a href=”google.co m”>google.com</a> has to remain as it is.



    I am using regex to find all the http(s) and a hrefs in the text. I am struck here.

    My code is,
    Code:
    Dim href As New Regex("(<a.*?>.*?</a>)", RegexOptions.IgnoreCase)
    
    Dim hrefs As New Regex("http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.IgnoreCase)
    
        
            Dim matchahref As MatchCollection = href.Matches(StrIn)
    
            Dim matches As MatchCollection = hrefs.Matches(StrIn)
    
     
    for each match in matches
    StrIn = Regex.Replace(StrIn, "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])", _
    
                                          String.Format("<a href=""{0}"">{0}</a>", match.ToString()))
    next
    I am trying to use Regex.Replace to replace my https. But I am unable to write the evaluate function.

    My regex.replace replaces all the values with a single value.



    Can some on please correct my regex.repalce. thank you.
Working...