0

我想做一个正则表达式来验证和解析下面的字符串:

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 = *

谢谢,

4

3 回答 3

1

我会这样做

\s*([^;]+);([^\s]+).*?\(\s*(\d+)\s*,\s*(\d+).*?;(\*)?

$1 = TESTE_CASE.PESSOAS
$2 = CO_CNPJ_CEI
$3 = 0000000000370000000000
$4 = 0000000000370000009999
$5 = *

于 2012-08-04T05:05:52.193 回答
1

您可以通过以下方式附上您需要的表达式()

( subexpression )
Captures the matched subexpression and assigns it a zero-based ordinal number.

并通过索引获取捕获的表达式

或使用命名组:

(?< name > subexpression)
Captures the matched subexpression into a named group.

并按名称获取捕获的表达式

于 2012-08-04T08:36:30.107 回答
0

试试这个:(\b(?!BETWEEN\b)[\w.]+\b|\*)

于 2012-08-04T06:04:09.863 回答