在C 中带有正则表达式的文本树
parsing tree of text with regex in C++
请帮助!我需要创建用于将以下文本解析到树中的代码/正面。
some text I want to ignore==toplevel==
some text, with newlines maybe
===nextlevel===
more text. This is a child node of 'toplevel'
===anotherchild===
this is a sibling of 'nextlevel' and a child of 'toplevel'====leaf====
this is a child of 'anotherchild'
====leaf2====
sibling of 'leaf' & child of 'anotherchild'
===child3===
this is a sibling of 'anotherchild' and 'nextlevel' and a child of 'toplevel'
等。你明白了。
我无法阻止子级别与高级级别匹配。我尝试过= {2},但是===和====仍然匹配。只需获得一个匹配,即提取所有文本以下" == toplevel =="将是一个开始。我似乎无法忽略/食用新线。
任何帮助!查理。
以下正则符合第一行:"^== [^=]"。也就是说,一条以两个相等的符号开始的线,然后是一个不是平等符号的东西。您可以在其他级别使用类似模式。
newline跳过/处理实际上取决于您如何阅读文本。如果可能的话,我会在输入例程中处理新线,而不是试图将它们与Regexes匹配。
只需匹配所有 =+(name)=+
字符串,然后计数代码中的= 的数量。
相关文章:
- 使用正则表达式regex_search在字符串中查找字符串
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- C++正则表达式无限循环
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- C++带有捕获组的正则表达式字符串文本
- 正则表达式 获取两个换行符之间的文本
- 带有Qt的正则表达式捕获一些文本
- 在C 中带有正则表达式的文本树
- 正则表达式是否足以分析大型文本
- 使用正则表达式检测类似"#smth"的文本(带有更多术语)
- 用于匹配 C++ 范围字符串文本的正则表达式 (L "..." )
- 使用boost正则表达式标记文本
- C++中的Regex,从正则表达式中获取文本任何部分的字符串
- 将文本附加到正则表达式匹配的一部分
- 如何从QInputDialog获得文本(正则表达式)
- 使用boost正则表达式解析文本文件
- 如何使用正则表达式提取文本中的所有名称
- 使用正则表达式在Embarcadero的C++生成器中将文本拆分为单个单词
- 如何将字符串转换为正则表达式文本
- 使用正则表达式从C++中的一行文本中提取数据