如何通过正则表达式来匹配类似环境的shell兼容变量赋值(How to match environment

编程入门 行业动态 更新时间:2024-10-27 20:33:41
如何通过正则表达式来匹配类似环境的shell兼容变量赋值(How to match environment-like shell-compatible variable assignment by regex)

我需要匹配这样的东西。 格式与centos中的/etc/locale.conf相同

LANG="en_US.UTF-8" LANG=en_US.UTF-8 LANG='en_US.UTF-8'

比赛结束后,需要提取“LANG”和“en_US.UTF-8”

I need to match something like this. format is the same with /etc/locale.conf at centos

LANG="en_US.UTF-8" LANG=en_US.UTF-8 LANG='en_US.UTF-8'

After match, need extract "LANG" and "en_US.UTF-8"

最满意答案

尝试:

^(\w+)=['"]?(.+?)['"]?$

您可能需要根据您的要求玩弄键/值的字符。

在这里看到它的行动

Try:

^(\w+)=['"]?(.+?)['"]?$

You may want to play with the character(s) of the key/value, depending on your requirements.

See it in action here

更多推荐

本文发布于:2023-07-07 09:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1061399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:赋值   变量   类似   环境   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!