[英]Please help me create a regular expression to parse my SQL statement
I want to extract 我要提取
FROM codes WHERE FieldName='ContactMethod' and IsNull(Deactived,'') != 'T'
from 从
SELECT FieldDescription,FieldValue FROM codes WHERE FieldName='ContactMethod'
and IsNull(Deactived,'') != 'T' order by fielddescription
using a regular expression. 使用正则表达式。 I have a regex like this:
我有这样一个正则表达式:
\FROM.*\order
which extracts 提取
FROM codes WHERE FieldName='ContactMethod' and IsNull(Deactived,'') != 'T' order
Also, how can I get rid of the capitalization? 另外,如何摆脱大写?
Thanks 谢谢
The trick here would probably be to capture the part you actually want with parens: 这里的技巧可能是使用parens捕获您实际想要的部分:
(FROM.*) order
This would greedily match until the last order
, if you want only until the first occurrence, match lazily: 这将贪婪地匹配到最后一个
order
,如果只希望直到第一次出现,则懒惰地匹配:
(FROM.*?) order
Expanding on Fabian Steeg's answer 扩展Fabian Steeg的答案
Dim regex As Regex = New Regex( _
"(FROM.*?) ORDER", _
RegexOptions.IgnoreCase _
Or RegexOptions.CultureInvariant _
Or RegexOptions.IgnorePatternWhitespace _
Or RegexOptions.Compiled _
)
Dim ms As MatchCollection = regex.Matches(InputText)
where InputText is of course your SQL query string. 其中InputText当然是您的SQL查询字符串。
ms(1) should hold the parentheses match ms(1)应该包含括号匹配
如果归结到它,则可以通过执行(F | f)(R | r)(O | o)(M | m)忽略大小写。
Interactive tools like RegexBuddy ($40) or The Regex Coach (free) would really help you to design and debug regular expressions for most platforms. 诸如RegexBuddy (40美元)或Regex Coach (免费)之类的交互式工具将真正帮助您设计和调试大多数平台的正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.