Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all. I am asking this for my wikipedia editing. I am not from the background of computer science but I edit wikipedia a lot.

I am using a software called as auto wiki browser to edit: brief intro to AWB - Wikipedia[^] AWB is a very powerful tool. It also supports modules.Wikipedia:AutoWikiBrowser/Custom Modules - Wikipedia[^] also regex.

I am running a find and replace task using awb. I wants to add some rules for skipping.
My exact problem in short: on wikipedia there are many pages called as disambiguation page for example: Robert Abel - Wikipedia[^]

This Robert Abel page lists all the persons named Robert Abel and nothing else. Ideally no wiki page should link to Robert Abel. The pages should link to particular Roberts. For example Robert Abel (animator)[^] or Robert Abel (footballer).

What I wants to do is: AWB makes a list of all the pages linking to Robert Abel (base page). I wants to search for Robert Abel and replace it with Robert Abel (animator). But if the text is "Robert Abel (footballer)" or "Robert Abel (racing driver)" then I wants to skip it.

What I have tried:

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
    Skip = false;
    Summary = "test";

    ArticleText = ArticleText.Replace("Robert Abel", "Robert Abel (animator)");

    return ArticleText;
}


I tried the above code in AWB module. But it addings "Robert Abel (animator) (animator)" if there is already "Robert Abel (animator)" in the article. I tried to add else parameter but it giving compilation error. This is faulty code:

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
    Skip = false;
    Summary = "test";

    ArticleText = ArticleText.Replace("Robert Abel", "Robert Abel (animator)");
if ArticleText = "Robert Abel (animator)" {
                    Skip = true;
                } else {
                    ArticleText.Replace("Robert Abel", "Robert Abel (animator)");
                }
    return ArticleText;
}


I wants to add few different rules. example: skip if "A", "B" or "C" is present. If D is present then change it to E. If "F" is present then change it to "G".

Please help me.
Posted
Updated 26-Aug-20 6:24am
v2
Comments
[no name] 26-Aug-20 15:08pm    
For c# if ArticleText = "Robert Abel (animator)" needs to be if (ArticleText == "Robert Abel (animator)")

1 solution

Quote:
How to perform find and replace with condition in C# and/or regex?

Exact match you want is not clear to me.
Give samples strings that must match and that must not.
Give details on rules.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
[update]
Quote:
thank you for the answer. For example I wants to find bare "Robert Abel" and replace it with "Robert Abel (animator)". I wants to skip if there is "Robert Abel (animator)" or "Robert Abel (footballer)" or "Robert Abel (racing driver)".

I think you need to rephrase your search to "Robert Abel" not followed by "(".
Try something like:
Robert Abel\W(?!\()
 
Share this answer
 
v3
Comments
Pallavi H Shinde 26-Aug-20 11:08am    
thank you for the answer. For example I wants to find bare "Robert Abel" and replace it with "Robert Abel (animator)". I wants to skip if there is "Robert Abel (animator)" or "Robert Abel (footballer)" or "Robert Abel (racing driver)".
Pallavi H Shinde 26-Aug-20 12:28pm    
I added the code. Please help @Patrice T @ppolymorphe
Patrice T 26-Aug-20 12:31pm    
Use Improve question to update your question.
Show new code and explain how it go wrong.
Pallavi H Shinde 26-Aug-20 13:29pm    
I did. Under "what i have tried".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900