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 to remove "i.e." from "This has been identified, i.e., found." using regex in R

string <- "This has been identified, i.e., found."

I want to remove "i.e." from the string. However, using

> gsub("i.e.", "", string) 
[1] "This has been tified, , found."

also removes "iden" from "identified". How do I write a regex that specifically targets "i.e."? I think the periods in "i.e." are triggering another regex expression than what I intended.

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

>Solution :

Use fixed = TRUE, otherwise . is identified as a meta-character. You can also use i\\.e\\..

gsub("i.e.", "", string, fixed = TRUE) 
#[1] "This has been identified, , found."
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