拆分表达式,但留下分隔符
Split expressions but leave separators
有这样的表达式:
name=="sometext"
value!=4
我想用像"=="answers"! "这样的字符串分隔符分割这样的表达式。="并保留这些分隔符,所以结果将是:
name=="sometext" -> [name] [==] ["sometext"]
value!=4 -> [value] [!=] [4]
如何用Boost或其他库完成?
对于boost,我会使用这个简单的正则表达式:
(.*?)(==|!=)(.*)
Edit: 提供表达式为字符串。
编辑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) «*»
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 提升精神:解析布尔表达式并简化为规范范式
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 使用正则表达式regex_search在字符串中查找字符串
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 概念中的cv限定符需要表达式参数列表
- 为什么constexpr的性能比正常表达式差
- 对于结构,表达式必须是可修改的ivalue
- 当用户键入分隔符时,停止getline()输入
- 当一个值是非常量但用常量表达式初始化时使用constexpr
- 带有多个字符分隔符的正则表达式
- 正则表达式以匹配数字的重复模式,后跟任何类型的分隔符?
- 使用正则表达式c++从单词和分隔符之间的字符串中提取所有子字符串
- Makefile中扩展正则表达式列表的分隔符
- 我可以在 c++ 中使用哪些正则表达式来解析分隔符、运算符、标识符和实数?
- 拆分表达式,但留下分隔符
- c++正则表达式.获取带分隔符的字符串
- c++正则表达式标记分隔符
- 如何在正则表达式匹配结果中包含分隔符