/^[a-z][ ][=][>][ ][a-z?][.?][a-z0-9]+[ ][=][ ]['?][a-z0-9]+['?]]/i
我试图弄清楚如何获得一个能识别一串lambda语法的rexex模式(在c#中使用)
对于字符串
"p => p = 'some random string'" //Must alow for single quotes
对于数字或布尔值
"p => p = true" /*or*/ "p => p = 25" //Must allow for a string without single quotes with no whitespace at all in the event there are no single quotes
此外,它必须允许一个单一的'。在选择' ='左边的字母中标志
"p => p.firstName = 'Jack'"
答案 0 :(得分:1)
首先,只是所有所需的>1 //1 test case
>3 //if condition as it should entered line 124
>inp[0] 3 //confirms 3 is inp[0]
>* //works as it should (if condn entered line 37)
>inp[0] *
>/ //works as it should
>inp[0] /
>+ //problem!! if condition not entered even though it should
//as inp[0] == '+' (line 61)
>inp[0] + //confirmation inp[0] is + right before if condition checked
>Segmentation fault (core dumped)
,只有字符类(例如[]
或[a-zA-Z]
)。
让我们按顺序完成您的步骤:
[_\$0-9]
([a-z])
([A-Z])
。([a-zA-Z])
中,以便稍后我们可以在后面引用它。()
(合并步骤2-4)就是这样,字面意思是:=>
。由于这些都不是特殊字符,因此无需转义。=>
集)中插入backref:()
\1
,然后是零个或多个字母数字字符:(\.\w)?
\w*
,这些字符都不需要转义,所以我们直接包含它:=
=
\d+
(我们使用负字符类来获取所有但 '[^']*'
)'
把所有这些放在一起,我们得到了最终的正则表达式:
|