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

标签 c# .net windows

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

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/

相关文章:

c# - 如何使用 Outlook 互操作检索发件人 smtp 电子邮件地址?

c# - HTTP 处理程序的相同 Asp.net 表单例份验证

c# - 使用 Roslyn 确定类是否抽象

c# - 如何在较高级别指定要使用的数据库隔离级别?

c# - 为什么我的表单在显示时会调整大小?

c# - 检查 WinForm 应用程序中输入的文本

sql - TNS监听器错误

c# - 防止使用 new() 构造对象

python子进程作为Windows中的不同用户

linux - 分离模式下 matlab 脚本编辑器窗口标题上的文件名