Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
In the following code I want to replace "ReplacedText" in the <Returns> sections of the xml comments to "NewText".


/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>
/// ReplacedText
/// </returns>
int Foo1(int x, int y)
{
return 0;
}

/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>
/// ReplacedText
/// </returns>
float Foo1(int x, int y)
{
return 0.0F;
}

The regular expression I used in the Find/Replace dialogbox of VS is
/// \<returns\>[.\n ]*\</returns\>

But this gives the error that searched string is not found.

Can you identify the mistake in my regular expression or suggest a different regular expression?

Thank you

fadi
Posted
Comments
OriginalGriff 20-Aug-10 4:37am    
Same thing - just undouble the back slashes:
FadiYoosuf 20-Aug-10 7:03am    
It also didn't work
What does the ^ symbol mean?
OriginalGriff 20-Aug-10 7:44am    
Firstly, when you add a comment to your own message, you (may) get an email - I don't, so I don't know you have said anything. Comment on my answer to alert me. Otherwise (like this) you will wait until I actually look to see if you have done anything. Could be minutes, could be days.
The "^" symbol says "Anything but this list" so the bit in square brackets matches anything but a '<' character.
It works for me in VS2008 - have you enabled regular expressions in the search box?

1 solution

Try this code:
public static Regex regex = new Regex(
      "\\<returns\\>([^\\<]*)\\</returns\\>",
    RegexOptions.IgnoreCase
    | RegexOptions.Singleline
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );

Get a copy of Expresso - it is free and really helps!
 
Share this answer
 
Comments
FadiYoosuf 20-Aug-10 4:08am    
Thank you for the answer.

But I would like to know about Visual Studio regular expression used in the Find/Replace dialog box of Visual studio.
FadiYoosuf 24-Aug-10 1:10am    
Sorry was the delayed reply.. I was out of station for some urgency.

It detects only if opening and closing Returns tag is in the same line.

If they are in the different line, VS Find dialog doesn't detect it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900