【发布时间】:2019-12-20 12:34:46
【问题描述】:
我有以下字符串:
root.single_product.baby->teenager_furn.others.
我想提取 .-sign 前面的每个字符串。我想出了这个:
Regex.Matches("root.single_product.baby->teenager_furn.others.", @"([\w]+)");
这给了我以下列表:
root
single_product
baby
teenager_furn
others
但我想要以下内容:
root
single_product
baby->teenager_furn
others
我怎样才能做到这一点?
【问题讨论】:
-
我很确定您正在寻找
Regex.Split或普通的string.Split函数。 -
@mypronounismonicareinstate 模式应该如何?
-
@Bryan 使用模式
\.表示Regex.Split或仅使用字符.表示string.Split -
@Bryan 'string [] split = myString.Split('.');'