【问题标题】:Remove text between two characters (parenthesis) in a string删除字符串中两个字符(括号)之间的文本
【发布时间】:2015-08-11 21:45:50
【问题描述】:

我正在处理一个项目,我想删除字符串中两个括号之间的文本。 示例:

std::string str = "I want to remove (this)."

我该怎么做呢? 我搜索了 google 和 stackoverflow 并没有找到任何东西。

【问题讨论】:

标签: c++ string


【解决方案1】:

我会为此使用正则表达式。查看我提供的链接。至于表达式使用下面的表达式

(\()(?:[^\)\\]*(?:\\.)?)*\)

那个人为我工作。

Conditionally replace regex matches in string

  • 不要混淆正则表达式和常用表达式。这不像:-):-O>:( 等更常见的表达方式虽然有效这些表达方式是互斥的表达方式,没有多少语言可以理解,但更常用。

【讨论】:

  • 如果值如下:std::string str = "I want to remove (this (one))."结果我想“我想删除”
猜你喜欢
  • 1970-01-01
  • 2019-01-24
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 2018-04-19
  • 1970-01-01
  • 1970-01-01
  • 2020-07-04
相关资源
最近更新 更多