后端是PostgreSQL服务器9.1。
我正在尝试构建 AdHoc XML 报告。报告文件将包含 SQL 查询,所有查询都必须以 SELECT 语句开头。 SQL 查询将带有参数。根据关联列的数据类型,这些参数将相应地呈现给用户以提供值。
一个粗略的 SQL 查询:
SELECT * FROM customers
WHERE
(
customers.customer_code=@customer_code AND customers.location=@location
AND customers.type=
(
SELECT type from types
WHERE types.code=@type_code
AND types.is_active = @type_is_active
)
AND customers.account_open_date BETWEEN @start_date AND @end_date
)
OR customers.flagged = @flagged;
我想从查询字符串中获取列名和参数的列表,并将它们放入字符串数组中并稍后进行处理。
我只能使用以下正则表达式匹配参数:
@(?)(?<parameter>\w+)
预计比赛:
customers.customer_code=@customer_code
customers.location=@location
types.code=@type_code
types.is_active = @type_is_active
customers.account_open_date BETWEEN @start_date AND @end_date
customers.flagged = @flagged
如何立即匹配“@Parameter”、“=”和“BETWEEN”?
我知道有点晚了,但为了未来的研究:
我认为这个正则表达式符合您的目的:
(\w+\.\w+(?:\s?\=\s?\@\w+|\sBETWEEN\s\@\w+\sAND\s\@\w+))
Check 这个 Regex101 小提琴 http://regex101.com/r/fW9zR0在这里,仔细阅读每个部分的解释。
基本上,它首先寻找您的customer.xxx_yyy
列,然后对于= @variable
or BETWEEN @variable1 AND @variable2
.
捕获的组:
MATCH 1
1. [37-75]
`customers.customer_code=@customer_code`
MATCH 2
1. [80-108]
`customers.location=@location`
MATCH 3
1. [184-205]
`types.code=@type_code`
MATCH 4
1. [218-251]
`types.is_active = @type_is_active`
MATCH 5
1. [266-327]
`customers.account_open_date BETWEEN @start_date AND @end_date`
MATCH 6
1. [333-361]
`customers.flagged = @flagged`
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)