Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

How to skip a particular term in regex find and replace?

$
0
0
Hello.
I am an editor at english wikipedia. I am adding template of wikiproject banners on the talkpages of articles which come under the scope of wikiproject. Basically, I am adding
{{WikiProject Espionage |importance=Mid |class=Start}}

to the talkpages of the articles. For that I use a tool called as auto wiki browser (AWB). Wikipedia:AutoWikiBrowser - Wikipedia[^]

Currently, I am using following module:
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
      {
          Regex header = new Regex(@"\{\{{WikiProject Espionage|{{WikiProject Espionage |{{WP Espionage|{{WikiProject Intelligence |", RegexOptions.IgnoreCase);
          Summary = "Added banner for [[WP:WikiProject Espionage|WikiProject Espionage]]";
          Skip = (header.Match(ArticleText).Success || !Namespace.IsTalk(ArticleTitle));
          if (!Skip)
              ArticleText = "{{WikiProject Espionage|class=|importance=|listas=}} \r" + ArticleText;
          return ArticleText;
      }


In the module, "WP Espionage", and "WikiProject Intelligence" are shortcuts/redirects to WikiProject Espionage. The module tells AWB to add the template to the article, and skip if any of these templates are already present. But the problem is, there is another wikiproject by the "Wikiproject Intelligence Agency". So my module is skipping the pages if there is Wikiproject Intelligence Agency already present on the page.

So my question is: is there a way to tell AWB to skip only if {{WikiProject Espionage, {{WP Espionage, and {{WikiProject Intelligence and to avoid the presence of {{Wikiproject Intelligence Agency ?

Any help will be appreciated a lot. Regards, —usernamekiran.

Viewing all articles
Browse latest Browse all 224

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>