How to remove text in brackets using a regular expression

后端 未结 3 1400
情深已故
情深已故 2020-12-18 20:36

I\'m looking for a regular expression which will perform the following:

INPUT: User Name (email@address.com)
OUTPUT: User Name

What would b

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 21:02

    This should do the job:

    var input = "User Name (email@address.com)";
    var output = Regex.Replace(input, @" ?\(.*?\)", string.Empty);
    

    Note the escaping of the ( and ) chars so that they aren't recognised as group markers.

提交回复
热议问题