【发布时间】:2014-10-16 06:16:49
【问题描述】:
我想使用正则表达式从字符串中提取子字符串,即。以下输入/输出列表显示了我真正想要的。我需要从字符串中提取部门过滤条件。 这里[dept]这个词是常量。那么在这种情况下,什么样的正则表达式对提取子字符串很有用
Input------------------------------------------------Output
Some conditions And [dept]=IT [dept]=IT
Some conditions And [dept]=IT Or [dept]=Account [dept]=IT Or [dept]=Account
Some conditions And [dept] IN ('IT','Account') [dept] IN ('IT','Account')
[dept]=IT And some conditions [dept]=IT
[dept]=IT Or [dept]=Account And some conditions [dept]=IT Or [dept]=Account
[dept] IN ('IT','Account') And some conditions [dept] IN ('IT','Account')
【问题讨论】:
-
只有这些字符串是您要从中获取 o/p 的地方,或者可能还有其他与您的输入类似的组合
-
是的,但部门值可能会改变。这些是可能的组合,字符串的结构应该是这样的
-
您似乎想要在第一个 3 案例之后的所有内容以及在最后三个案例之前的所有内容,这就是您想要的吗?
-
@jadavparesh06 是的,当然
-
这看起来很像从任意 SQL 查询中提取信息,我 99.85% 确信这不是您应该使用正则表达式解决的任务。