-2

Remove in side '(data)' in string python, I have string like this "i am learning python programming, (Because) it is easy langue for new learner(s)" i want to remove first (Because) data only. In side (data) may vary anything. Not constant.

1 Answers1

0

You can use regex:

>>> import re
>>> string = "i am learning python programming, (Because) it is easy langue for new learner(s)"
>>> ''.join(re.split(r"\([^)]*\)", string))
'i am learning python programming,  it is easy langue for new learner'

The pattern searches for opening brace, then any stuff except closing brace, then closing brace.

Vicrobot
  • 3,795
  • 1
  • 17
  • 31