正则表达式匹配ini值 [英] Regex to match ini value

查看:134
本文介绍了正则表达式匹配ini值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试匹配ini行的值的姓氏。

I'm trying to match the last name of a value of an ini line.

foo.bar.far.boo = "some value"

我可以匹配'boo ='但我只需要'boo'

I can match 'boo =' but I just need 'boo'

我做(\ w +)\ s * = 但它符合等号,但我不知道我希望它匹配。

I do (\w+)\s*= but it matches the equal signs, but I don't want it to be matched.

顺便说一句,如果没有像以下这样的子值,我应该可以得到:

By the way, I should be able to get if there is no sub values like :

foo = "value"


推荐答案

使用

\w+(?=\s*=)

(?= ...)积极的先行断言,意思是断言封闭的正则表达式可以在这里匹配,但不要让它成为一部分比赛本身。

(?=...) is a positive lookahead assertion, meaning "assert that the enclosed regex can be matched here, but don't make it part of the match itself".

因此正则表达式匹配一个或多个字母数字字符,当且仅当它们后面跟着(可选的空格和等号)时。

So the regex matches one or more alphanumeric characters if and only if they are followed by (optional whitespace and) an equals sign.

这篇关于正则表达式匹配ini值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆