How to omit replacement in somepart of text using regular expression?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • padmaneha
    New Member
    • Sep 2008
    • 17

    How to omit replacement in somepart of text using regular expression?

    How to omit replacement in somepart of text using regular expression?

    For ex:

    If i want to replace mumbai with mumbai/aaa.com but if i have an anchor tag

    <a href="/mumbai/bbb.com>mumbai</a>
    then in the anchor tag too the replacement takes place which should not be done..

    How to solve this problem?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Post the code you have used for the replacement.

    Comment

    • padmaneha
      New Member
      • Sep 2008
      • 17

      #3
      Regex.Replace(s tr1, m.Result("$2"), sRep);


      str1 is the htm file where the string is to get modified and srep is the string that replaces ..

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        See the specs for the Replace . There are overloads that allow you to specify how many times the replacement can occur.

        Comment

        • padmaneha
          New Member
          • Sep 2008
          • 17

          #5
          Originally posted by padmaneha
          Regex.Replace(s tr1, m.Result("$2"), sRep);


          str1 is the htm file where the string is to get modified and srep is the string that replaces ..

          can u please write a code for example?

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            The code examples are there in the specs for that method. It's just a matter of picking the correct Replace method from the class which also accepts an integer specifying the number of replacements to do.

            Comment

            Working...