Regex to replace invalid characters

后端 未结 3 1911
甜味超标
甜味超标 2020-12-07 02:16

I don\'t have much experience with RegEx so I am using many chained String.Replace() calls to remove unwanted characters -- is there a RegEx I can write to streamline this?<

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 02:56

    Character classes to the rescue!

    string messyText = GetText();
    string cleanText = Regex.Replace(messyText.Trim().ToUpper(), @"[,:.;/\\\n\t\r ]+", "")
    

提交回复
热议问题