代码之家  ›  专栏  ›  技术社区  ›  Arthur Frankel

在C中使用regex.split的多个分隔符#

  •  3
  • Arthur Frankel  · 技术社区  · 15 年前

    假设您需要使用各种分隔符拆分字符串,包括换行符(/r,/n)和其他一些“特殊”字符串。

    例如:

    This is a sample %%% text &&& that I would 
    like to split %%% into an array.
    

    我希望得到的字符串数组中包含以下内容(内容通过索引)

    [0]This is a sample
    [1]text
    [2]that I would
    [3]like to split
    [4]into an array.
    

    我想使用c regex.split()函数。在所有分隔符上匹配的regex表达式是什么?

    提前谢谢

    3 回复  |  直到 15 年前
        1
  •  5
  •   Eric Olsson    15 年前

    仅供参考,vanilla string.split()方法有一个重载,它接受一个字符串数组用作分隔符。 Here's 一个指向描述它的msdn页面的链接。

        2
  •  6
  •   David    15 年前

    %%%|&&& 应该这样做。

        3
  •  -3
  •   Curtis White    15 年前

    我还没有准备好这个解决方案。您可以创建一个类并与之进行比较。您可以通过以下方式获得服务:

    http://www.regexbuddy.com/