Home > Net >  How do I remove all questions from a text with regex and stringr?
How do I remove all questions from a text with regex and stringr?

Time:11-05

I have the following string:

"This is a question? This is an answer This is another question? This is another answer."

What I want to do is create a regex that will match all the questions so I can remove them. In this case the preceding answer or sentence doesn't always end with a '.' (full stop). So what I am looking for is to match sentences that end with a question mark and start with a capital letter.

What I want to match:

"This is a question?" and "This is another question?"

I work in R so I prefer an answer with stringr, but I'm mostly interested in the regex that I should apply.

CodePudding user response:

This should do the trick in regex: ([A-Z][^A-Z?]*\?)

  • Related