-5

I'm working on a project and I want to remove text between two parentheses in a string. Example:

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

How would I go about doing that? I've searched google and stackoverflow an haven't found anything.

user2864740
  • 60,010
  • 15
  • 145
  • 220
Smile
  • 3
  • 6

1 Answers1

1

I'd use a regular expression for that. Check out the link I provided. As for the expression to use the following expression

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

That guy worked for me.

Conditionally replace regex matches in string

  • Do not get regular and common expressions confused. This is not like the more common expression of :-) or :-O or >:( All-though effective These expressions are mutually exclusive expressions that not many languages understand but are more commonly used.
Community
  • 1
  • 1
Syrrus
  • 79
  • 9
  • What happend here if the value is the following: std::string str = "I want to remove (this (one))." and I would like to have as a result "I want to remove " – ypriverol Sep 04 '17 at 19:50