gpt4 book ai didi

c# - 正则表达式问题 C#

转载 作者:可可西里 更新时间:2023-11-01 10:56:26 26 4
gpt4 key购买 nike

我在尝试使用以下正则表达式时遇到问题:

string profileConfig = File.ReadAllText(str);

string startIndex = "user_pref(\"network.proxy.autoconfig_url\", \"";
string endIndex = "\"";

var regex = startIndex + "(.*)" + endIndex;
// Here we call Regex.Match.
Match match = Regex.Match(profileConfig,
regex,
RegexOptions.IgnoreCase);

// Here we check the Match instance.
if (match.Success)
{
// Finally, we get the Group value and display it.
string key = match.Groups[1].Value;
MessageBox.Show(key);
}

我得到错误:

Additional information: parsing "user_pref("network.proxy.autoconfig_url", "(.*)"" - Not enough )'s.

我的正则表达式是否存在某种形式的错误?

最佳答案

如果您打算匹配字符 ( 字面意思是:

,请转义第一个括号
string startIndex = "user_pref\\(\"network.proxy.autoconfig_url\", \"";

关于c# - 正则表达式问题 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com