不会写正则表达式,大神些帮帮忙!

Null_Reference 2020-07-06 01:53:00
现在有个需求、需要得到配置文件里面的配置信息。想要通过正则表达式来获取

我想要获取每个server 里面的 字段信息 比如 listen、server_name 最终就是想把这个配置文件转成一个List<Server> 这样的

文本内容:


http {
include mime.types;

server {
listen 90;
server_name www.n.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 91;
server_name www.c.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}


}

}
...全文
7385 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Null_Reference 2020-07-07
  • 打赏
  • 举报
回复
引用 2 楼 haiancdp0503 的回复:
搜下 HOCON 类型文件怎么解析
搜过了 没看见C#语言的
Null_Reference 2020-07-07
  • 打赏
  • 举报
回复
引用 1 楼 github_36000833 的回复:
这样的需求,不能单用正则。 你可能需要逐行读取信息,利用一些状态量,来组装你需要的数据。 比如说, 读到‘{’就是进入‘区块’,碰到‘}’就是结束当前‘区块’; 读到‘#'就是作为注释忽略当前行,等等等等...
开始也是这种想法 感觉有点傻 并且 比如我要获取root 这个参数的时候就不好使了。下面还有其它root配置
haiancdp0503 2020-07-06
  • 打赏
  • 举报
回复
搜下 HOCON 类型文件怎么解析
github_36000833 2020-07-06
  • 打赏
  • 举报
回复
这样的需求,不能单用正则。 你可能需要逐行读取信息,利用一些状态量,来组装你需要的数据。 比如说, 读到‘{’就是进入‘区块’,碰到‘}’就是结束当前‘区块’; 读到‘#'就是作为注释忽略当前行,等等等等...

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧