0

我需要找到所有Response.Redirect();不以true, true); 我认为在 Visual Studio 中使用带有搜索的 Regex 是找到它们的最佳选择,但我不知道如何制作该 regex。在response.redirect可以是任何东西,但它不能结束true, true); 那些是我想要找到的。

关于正则表达式的任何想法?

4

2 回答 2

1

我认为这应该有效:

Response\.Redirect\s*\(.*?(?<!true\s*\,\s*true\s*)\);

搜索“Response.Redirect”, - 后跟 0 个或多个空格 - 后跟 ( - 后跟任何字符的最短序列 - 不以 true、true 结尾);

于 2012-04-19T08:34:58.997 回答
0

试试这个:

true, true\);$

解释:

  • ) 是特殊字符,因此您需要对其进行转义。
  • 最后的 $ 将匹配以正则表达式结尾的字符串。

要匹配 X 而不是匹配 Y,请尝试:

$regex1 = '/^Response\.Redirect\(/';
$regex2 = '/true, true\);$/';

然后:

if (preg_match($regex1, $s) && !preg_match($regex2, $s)) { // match } else { // not match }

例子:

$s = 'Response.Redirect("something", true, true);'; // false
$s = 'Response.Redirect("something");'; // true
$s = '("something", true, true);'; // false

抱歉,PHP 中的示例。但是您可以调整正则表达式和逻辑。

于 2012-04-19T08:05:43.883 回答