-1

I have for example:

Text=‘ Text1. Text2(Gino).Text(Ant)text. Text4. Text(Fi).’

Desired output:

Text=‘Text2(Gino). Text(Ant)text. Text(Fi)’
jay.sf
  • 60,139
  • 8
  • 53
  • 110
Anthony
  • 17
  • 3

2 Answers2

1

You seem to only want the parts of the text that has parentheses, and the parts are delimited by dots.

Try this regex:

\w+\(\w+\)\w*\.\s*

Finding all the matches and joining all of them will produce the string you desire.

Explanation:

The regex matches some word characters (\w+), followed by an open parenthesis \( and some more word characters (\w+) followed by a closing parenthesis \), and optionally followed by some more word characters (\w*). After that it looks for a dot and optional whitespace characters.

Sweeper
  • 213,210
  • 22
  • 193
  • 313
0

Not sure if this is what you were looking for:

Text <- "Text1. Text2(Gino).Text(Ant)text. Text4. Text(Fi)."
Text <- gsub("Text1. ", "", Text, fixed=TRUE)
Text <- gsub("Text4. ", "", Text, fixed=TRUE)
Text
[1] "Text2(Gino).Text(Ant)text. Text(Fi)."

Changed fixed=TRUE to fixed=FALSE if you want to use regular expressions.

Adam Smith
  • 2,584
  • 2
  • 20
  • 34