RegEx for LINQ之类的语法 [英] RegEx for LINQ like syntax

查看:65
本文介绍了RegEx for LINQ之类的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,格式为:

I have a string in the format:

MyList.Where(abc).GroupBy(def).Sum(ghi)

何处& GroupBy部分是可选的,函数的参数也是可选的.

The Where & GroupBy parts are optional as is the argument to the function, so.

ThisList.Count

也是有效的.

我正在尝试找到一个与此匹配的RegEx字符串并返回值:
列表名称(例如MyList),where条件(例如abc),GroupBy属性(例如def),函数名称(例如Sum)和函数属性(例如ghi).

I'm trying to find a RegEx string that will match this and return the values:
The List name (e.g. MyList), the where condition (e.g. abc), the GroupBy attribute (e.g def), the function name (e.g. Sum) and the function attribute (e.g. ghi).

说明:
列表名称是一个单词
abc可以是一个复杂的表达式,但是不会有用引号引起来的右括号
def将是一个单词
ghi将是一个单词或由,"分隔的单词列表.

Clarification:
The List name is one word
abc can be a complex expression, but there will be no close brackets which are not in quotation marks
def will be a single word
ghi will be a single word or a list of words separated by ","

推荐答案

(?<list>\w+)\s*
([.]\s*Where\s*[(]\s*(?<wherearg>.*?)\s*[)]\s*)?
([.]\s*GroupBy\s*[(]\s*(?<groupbyarg>.*?)\s*[)]\s*)?
[.]\s*(?<func>\w+)\s*[(]\s*(?<funcarg>.*?)\s*[)]

这篇关于RegEx for LINQ之类的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆