When renaming categories, my bot treats it as a remove/add. First it checks to see if the article is already in category 2, in which case it just removes it from 1. If it's not in 2, it replaces category 1 with category 2.
The code:
-----
pl3[i].Load(); //loads article
if (Regex.IsMatch(pl3[i].text, @"(?i)\[\[(" + site.namespaces["14"] + "|" + Site.wikiNSpaces["14"] + ") *: *" + pl[1].title + @" *(]]|\|)")) //checks to see if article is already in category 2
{
pl3[i].RemoveFromCategory(pl[0].title); //removes it if it is
}
else
{
pl[0].RemoveNSPrefix();
pl[1].RemoveNSPrefix();
pl3[i].text = pl3[i].text.Replace("[[Category:" + pl[0].title,"[[Category:" + pl[1].title); //replaces category 1 with category 2
-----
My problem occurs when category 1 is different than category 2 by capitalization only (for example, changing Category:Foo bar to Category:Foo Bar). On the first article, it works fine. But for every other article, it simply removes category 1.
I think the problem is due to RemoveNSPrefix. If I don't use it, the replace doesn't work.
Any ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When renaming categories, my bot treats it as a remove/add. First it checks to see if the article is already in category 2, in which case it just removes it from 1. If it's not in 2, it replaces category 1 with category 2.
The code:
-----
pl3[i].Load(); //loads article
if (Regex.IsMatch(pl3[i].text, @"(?i)\[\[(" + site.namespaces["14"] + "|" + Site.wikiNSpaces["14"] + ") *: *" + pl[1].title + @" *(]]|\|)")) //checks to see if article is already in category 2
{
pl3[i].RemoveFromCategory(pl[0].title); //removes it if it is
}
else
{
pl[0].RemoveNSPrefix();
pl[1].RemoveNSPrefix();
pl3[i].text = pl3[i].text.Replace("[[Category:" + pl[0].title,"[[Category:" + pl[1].title); //replaces category 1 with category 2
-----
My problem occurs when category 1 is different than category 2 by capitalization only (for example, changing Category:Foo bar to Category:Foo Bar). On the first article, it works fine. But for every other article, it simply removes category 1.
I think the problem is due to RemoveNSPrefix. If I don't use it, the replace doesn't work.
Any ideas?
Try removing (?i) inline option from first regular expression. That (?i) means "IgnoreCase". I think that is the reason of malfunction.