【问题标题】:C# regex fails to split string by pipe delimiter [duplicate]C#正则表达式无法通过管道分隔符分割字符串[重复]
【发布时间】:2018-05-19 10:26:30
【问题描述】:
string query = "A|B";

接下来两行的输出等于"%A%|%B%",而“A%B”是预期的!

query = Regex.Replace(query, "|", "%");
query = Regex.Replace(query, @"|", "%");

为什么?

【问题讨论】:

    标签: c# regex split


    【解决方案1】:

    The | is a special character of regexes, it means "or"。你必须逃脱它。

    query = Regex.Replace(query, @"\|", "%");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      相关资源
      最近更新 更多