Help Me Writing a Simple Regular Expression
I have the following text:
txtAddressSup.Text
I want the Sup
to be replaced by Cus
while the whole text remains as is. I have many texts that are in this form开发者_如何转开发at:
xxxxxxxSup.xxxxx
It's not clear from your question but I guess you are doing this in Visual Studio. Visual Studio uses a strange brand of regular expressions that is incompatible with most other engines. Try this:
Find: {:i}Sup{\.:i} Replace: \1Cus\2
Explanation:
{...} Tag expression (usually called a capturing group in other engines) :i Identifier Sup Literal string "Sup" \. Literal string "."
To get help with this either see the description of the syntax for Visual Studio regular expressions on MSDN or press the black triangle next to the input fields to get quick help.
why do you need to use regex? Won't a simple string replace work?
myString = myString.Replace("Sup.","Cus.");
The regex to match those would be (common Regex syntax, not the one from Visual Studio):
\BSup(?=\.\w+)
Just replace the matches with Cus
精彩评论