Computing desk | ||
---|---|---|
< July 26 | << Jun | July | Aug >> | July 28 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
Hi guys! Could somebody help out with C#? If I have regex pattern ([^\.])<ref>.*?<\/ref> (Lorem|Foo)? bar
and string "Foo<ref>Foo</ref> Foo bar
", how to change to lowercase only the second match (in this case - the "Foo", that comes after ref)? If I would need to lowercase everything, I would use something like (tested with other string, so this one may contain some small bugs, but you got the idea):
string text = @"Foo<ref>Foo</ref> Foo bar";
string pattern = @"([^\.])<ref>.*?<\/ref> (Lorem|Foo)? bar";
text = Regex.Replace(text, pattern, delegate(Match match)
{
string v = match.ToString();
return v.ToLower();
});
Note, that this is for AWB module, so it might not look very C#-ish. --Edgars2007 (talk/contribs) 09:16, 27 July 2016 (UTC)
string text = @"Foo<ref>Foo</ref> Foo bar";
string pattern = @"([^\.])<ref>.*?<\/ref> (Lorem|Foo)? bar";
text = Regex.Replace(text, pattern, delegate(Match match)
{
return match.Groups[2].Value.ToLower(); // second capture to lower case
});
string text = @"Foo<ref>Foo</ref> Foo bar";
string pattern = @"([^\.]<ref>.*?<\/ref> )(Lorem|Foo)?( bar)"; // captures modified
text = Regex.Replace(text, pattern, delegate(Match match)
{
return match.Groups[1].Value + match.Groups[2].Value.ToLower() + match.Groups[3].Value; // second capture to lower case
});
Regex.Replace
replaces all of text
with whatever you return from the delegate()
, right? If you want to keep bits of text
then you need to capture them, modify the captures to suit, reassemble, and return the result. match.Groups[0]
is the raw match; match.Groups[1]
is the first capture, etc.How do I install a .xwp file? Can someone help me please? I collected some clock gadgets a while back from this website. After downloading and opening the WinRar folder, I found a .xwp file - if I re-extract this .xwp file, I find a Widget folder which consisting all the bits. Problem is I still don't know how to install... -- Apostle (talk) 18:12, 27 July 2016 (UTC)