我想创建一个正则表达式来验证和解析下面的字符串:
TESTE_CASE.PESSOAS;CO_CNPJ_CEI BETWEEN (0000000000370000000000, 0000000000370000009999);*
使用以下正则表达式我可以验证字符串:
\s*\w+.\w+\s*;\s*\w+\s+(?i)BETWEEN\s+\(\s*\w+\s*,\s*\w+\s*\)\s*;\s*\*\s*
解析此字符串的最佳方法是什么?我需要输出如下:
String1 = TESTE_CASE.PESSOAS
String2 = CO_CNPJ_CEI
String3 = 0000000000370000000000
String4 = 0000000000370000009999
String5 = *
谢谢,
答案 0 :(得分:1)
我会这样做
\s*([^;]+);([^\s]+).*?\(\s*(\d+)\s*,\s*(\d+).*?;(\*)?
$ 1 = TESTE_CASE.PESSOAS
$ 2 = CO_CNPJ_CEI
$ 3 = 0000000000370000000000
$ 4 = 0000000000370000009999
$ 5 = *
答案 1 :(得分:1)
您可以按()
:
( subexpression )
Captures the matched subexpression and assigns it a zero-based ordinal number.
并通过索引
获取捕获的表达式或使用命名组:
(?< name > subexpression)
Captures the matched subexpression into a named group.
并通过名称
获取捕获的表达式答案 2 :(得分:0)
试试这个:(\b(?!BETWEEN\b)[\w.]+\b|\*)