我在正则表达式方面遇到了一些问题。
我有以下类型的字符串,我需要从中解析/获取数据
'Account'.Search = "[Id] is NULL OR NAME = ""0%"""
'Account'.Sort = "NAME, Address"
'Bank Objectives'.Search = "[Active Flg] = "Y""
'Bank'.Search = "[Id] is NULL"
'Bank'.Sort = "Transit"
'Bank Goals'.Search = "[Active Flg] = 'Y'"
.......
以下表达式似乎有效
\s*(?:(?<search>(?:(=['"])?(?:.*)\1|.*)\.Search[^"']*(?:(=['"])?(?:.*)\1|.*))\s*$?(?<sort>(?:(=['"])?(?:.*)\1|.*)\.Sort[^"']*(?:(=['"])?(?:.*)\1|.*))?\s*$?)
我可以得到像
search: 'Account'.Search = '[Id] is NULL OR NAME = ''0%'''
sort: 'Account'.Sort = "NAME, Address"
search: 'Bank Objectives'.Search = "[Active Flg] = "Y""
search: 'Bank'.Search = "[Id] is NULL"
sort: 'Bank'.Sort = "Transit"
search: 'Bank Goals'.Search = "[Active Flg] = 'Y'"
但是,如果输入字符串没有换行符,那么我开始得到
search: 'Account'.Search = '[Id] is NULL OR NAME = ''0%''''Account'.Sort = "NAME, Address"
我基本上从输入字符串中得到的是
Account
Search = "[Id] is NULL OR NAME = ""0%"""
Sort = "NAME, Address"
Bank Objectives
Search = "[Id] is NULL OR NAME = ""0%"""
Sort = ""
.....
也(=['"])?(?:.*)\1|.*)
假设匹配引号,但它似乎也不起作用。
最终目标是将字符串传递[Id] IS NULL or Name =""0%"""
给表达式编辑器,允许用户进行更改,然后只更新整个字符串的搜索部分,所以如果用户想要以 开头的帐户名bob
,我需要生成
'Account'.Search = "Name like 'bob%'"
'Account'.Sort = "NAME, Address"
'Bank Objectives'.Search = "[Active Flg] = "Y""
'Bank'.Search = "[Id] is NULL"
'Bank'.Sort = "Transit"
'Bank Goals'.Search = "[Active Flg] = 'Y'"
.......
我已经构建了那块,它正在解析这个可以有多个条目的字符串。字符串也可以只包含
"Name like 'bob%'"
所以我要弄清楚它实际上是
'Account'.Search = "名字像'bob%'"
所以我需要知道输入字符串是否与正则表达式匹配