Removing word or character from string followed by space or before space in c#

前端 未结 6 1248
悲哀的现实
悲哀的现实 2021-01-25 00:55

I have a string

string name = \"AL QADEER UR AL REHMAN AL KHALIL UN\";

How would I remove all characters AL, UR,

6条回答
  •  半阙折子戏
    2021-01-25 01:24

    I am loading that list from database, and can be change any time, how do use this in regex when changes occur

    okay then, the length would always be 2?

    no, but not be greater than 4

    public static void Main()
    {
        var input = "AL QADEER UR AL REHMAN AL KHALIL UN AAA BBB";
        Regex re = new Regex(@"\b\w{1,4}\b");
        var result = re.Replace(input, "");
        Console.WriteLine(result);
    }
    

    OUTPUT:

    QADEER REHMAN KHALIL
    

    dotNetFiddle

提交回复
热议问题