有这样的表达:
name=="sometext"
value!=4
Run Code Online (Sandbox Code Playgroud)
我想用"=="和"!="之类的字符串分隔符拆分这些表达式并保留这些分隔符,结果将是:
name=="sometext" -> [name] [==] ["sometext"]
value!=4 -> [value] [!=] [4]
Run Code Online (Sandbox Code Playgroud)
如何使用Boost或其他库来完成?
有了提升,我会使用这个简单的正则表达式:
(.*?)(==|!=)(.*)
Run Code Online (Sandbox Code Playgroud)
编辑:前提是表达式是一个字符串.
编辑2:正则表达式的解释
// (.*?)(==|!=)(.*)
//
// Match the regular expression below and capture its match into backreference number 1 «(.*?)»
// Match any single character that is not a line break character «.*?»
// Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
// Match the regular expression below and capture its match into backreference number 2 «(==|!=)»
// Match either the regular expression below (attempting the next alternative only if this one fails) «==»
// Match the characters “==” literally «==»
// Or match regular expression number 2 below (the entire group fails if this one fails to match) «!=»
// Match the characters “!=” literally «!=»
// Match the regular expression below and capture its match into backreference number 3 «(.*)»
// Match any single character that is not a line break character «.*»
// Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
127 次 |
| 最近记录: |