आप जा सकते हैं और छोटे अक्षरों कि बैकस्लैश का एक असमान संख्या से पहले नहीं कर रहे हैं के लिए खोज:
(?<!(?<!\\)(?:\\\\)*\\)\p{Ll}+
फिर एक MatchEvaluator
को मैच गुजरती हैं, यह अपरकेस और मूल स्ट्रिंग में पाठ बदलने। मैं सी # पता नहीं है, तो यह सही दूर काम नहीं कर सकते (कोड स्निपेट लिया और RegexBuddy से थोड़ा संशोधित), लेकिन यह एक शुरुआत है:
string resultString = null;
resultString = Regex.Replace(subjectString,
@"(?<! # Negative lookbehind:
(?<!\\)(?:\\\\)*\\ # Is there no odd number of backslashes
| # nor
\(\?<?\p{L}* # (?<tags or (?modifiers
) # before the current position?
\p{Ll}+ # Then match one or more letters",
new MatchEvaluator(ComputeReplacement), RegexOptions.IgnorePatternWhitespace);
public String ComputeReplacement(Match m) {
// You can vary the replacement text for each match on-the-fly
return @"\0".ToUpper(); // or whatever is needed for uppercasing in .NET
}
स्पष्टीकरण:
(?<! # assert that the string before the current position doesn't match:
(?<!\\) # assert that we start at the first backslash in the series
(?:\\\\)* # match an even number of backslashes
\\ # match one backslash
)
\p{Ll}+ # now match any sequence of lowercase letters
स्रोत
2011-05-27 10:36:55
कर सकते हो अपने पैटर्न स्ट्रिंग पर '[^ AZ]' – diEcho
'ToUpper() 'का उपयोग करें। यह विशेष वर्णों को प्रभावित नहीं करना चाहिए। – RBaarda
मुझे डर है कि यह कर सकता है, उदाहरण के लिए \ w या \ s का अलग अर्थ है जब ToUpper() - ed – petho