C# 如何读取apache vhosts文件
我正在尝试创建一个基本的 C# 应用程序来管理我的 Apache vHosts 文件,因此我不必编辑原始文件来设置新的 vhost
现在我正在尝试使用正则表达式来匹配 Vhosts,但这不起作用,有人会吗?为我提供一个工作示例,
这就是我当前拥有的
StreamReader reader = new StreamReader(filePath);
string content = reader.ReadToEnd();
string regEx = "<VirtualHost .*>.*</VirtualHost>";
foreach (Match match in Regex.Matches(content, regEx, RegexOptions.IgnoreCase))
{
MessageBox.Show(match.Value);
}
,但如果我使用 string regEx = "
它可以返回打开的虚拟主机标签,但不会返回任何应该返回所有内容的内容
I'm trying to create a basic C# application for managing my Apache vHosts file so i dont have to edit the file raw to setup a new vhost
Now i'm trying to get regex to match the Vhosts but this is not working would some one proivde me a working example
This is what i currently have
StreamReader reader = new StreamReader(filePath);
string content = reader.ReadToEnd();
string regEx = "<VirtualHost .*>.*</VirtualHost>";
foreach (Match match in Regex.Matches(content, regEx, RegexOptions.IgnoreCase))
{
MessageBox.Show(match.Value);
}
This fails but if i use string regEx = "<VirtualHost .*>.*"
it works to the point it returns the opening vhosts tag but will not return any of the content where it should return every thing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将此作为您的正则
表达式编辑:
在
[^<]*
周围添加了圆括号,因此它将返回标签之间的文本作为匹配项之一。Try this as your regexp
EDITED:
Added round brackets around the
[^<]*
, so it would return text between the tags as one of the matches.