I have for example:
Text=‘ Text1. Text2(Gino).Text(Ant)text. Text4. Text(Fi).’
Desired output:
Text=‘Text2(Gino). Text(Ant)text. Text(Fi)’
I have for example:
Text=‘ Text1. Text2(Gino).Text(Ant)text. Text4. Text(Fi).’
Desired output:
Text=‘Text2(Gino). Text(Ant)text. Text(Fi)’
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.
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.