我有一大段文字,例如:
姓名=Long John Silver;职业=厨师;爱好=盗版
并使用 Boost::regex 库我试图获取每个属性的值,所以我有以下名称的正则表达式:
regex(".*Name=([^;$]*).*")
我将其理解为“在Name=之后获取所有内容,直到找到 ; 或行尾”。但是我regex_match
得到的只是“长”,没有空格。当然,我一直在尝试几种 RE 组合,但我无法解决。
有什么线索吗?干杯。
No, inside a character class (the square brackets) the $
has no special meaning. It simply matches the literal '$'
.
Try this regex:
Name=([^\s;]*)
The character class [^\s;]
matches any character except a whitespace character and a semicolon. The name is now captured inside the first match-group.
EDIT:
And if you want to match the entire name "Long John Silver", use this regex:
Name=([^;]*)