[英]AND in Regular expression
You could start off from something like so: public void init\\(\\).*?\\{.*?select\\s*\\*\\s*from
(with the s
flag, so that the .
can match new line characters) example here . 您可以从类似这样的内容开始:
public void init\\(\\).*?\\{.*?select\\s*\\*\\s*from
(带有s
标志,以便.
可以匹配换行符) 这里的例子。
The issue with your approach is that: 您的方法存在的问题是:
\\
. \\
进行转义。 .
) does not match a new line, so we need to add the s
flag. .
)与换行符不匹配,因此我们需要添加s
标志。 In C#, this is available as RegexOptions.SingleLine
. RegexOptions.SingleLine
。 PS If you want to make it more robust, you can use something like so: public\\s+void\\s+init\\s*\\(\\).*?\\{.*?select\\s*\\*\\s*from
. PS如果要使其更强大,可以使用类似以下的方法:
public\\s+void\\s+init\\s*\\(\\).*?\\{.*?select\\s*\\*\\s*from
。 This would allow you some more freedom when it comes to having multiple spaces between keywords. 当关键字之间有多个空格时,这将为您提供更大的自由度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.