Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"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.

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading