c# - 使用正则表达式分割嵌套参数

标签 c# regex parsing split

任何人都可以帮助使用正则表达式方法(或其他方法)来分割此字符串

string text = "Item -> \"Elephant\", Branches -> 10, Color -> RGB[1, 0, 1], Style -> {Font -> \"Courier New\", Size -> 7}, Display -> True";

获取

List<string> directives = new List<string>();

包含以下五个字符串?

"Item -> \"Elephant\""
"Branches -> 10"
"Color -> RGB[1, 0, 1]"
"Style -> {Font -> \"Courier New\", Size -> 7}"
"Display -> True"

最佳答案

您可以使用以下内容进行拆分:

,\s*(?=\s*[^,]+-)

参见DEMO

关于c# - 使用正则表达式分割嵌套参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36448450/

相关文章:

c# - 单元测试错误 "Object reference not set to an instance of an object."

c# - XNA 二维绘图库

Javascript RegEx 和 XMLHttpRequest

python - 解析 Python 文件并评估所选函数

Python 为属性文件中的特定键设置值

c# - 如果文件超过 500mb,DownloadFileAsync 应用程序没有响应?

c# - 在 asp.net 中标准化 jpeg 大小

Python:从格式化字符串中提取字段

python - 当测试与正则表达式 : 'NoneType' object has no attribute 'group' 不对应时,我的脚本返回错误

java - BeanIO InvalidRecordGroupException 给出错误的行号