NAZIYA GULNAAZ
NAZIYA GULNAAZ

Reputation: 11

how to extract word string contains specific letter in r

Hi Team I have 100+ rows with https://.....

like below

https://clinicaltrials.gov/show/NCT05301842
https://am.asco.org/sites/am.asco.org/files/AM17-Proceedings.pdf; https://ascopubs.org/doi/10.1200/JCO.2017.35.15_suppl.11520; https://clinicaltrials.gov/ct2/show/NCT01564368; https://pubmed.ncbi.nlm.nih.gov/30179110/; https://pubs.rsna.org/doi/10.1148/radiol.2018180273?url_ver=Z39.88-2003&rfr_id=ori:rid:crossref.org&rfr_dat=cr_pub%20%200pubmed; https://rad.washington.edu/about-us/academic-sections/breast-imaging/research/; https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6283325/
https://clinicaltrials.gov/ct2/show/NCT05382741; https://www.clinicaltrialsregister.eu/ctr-search/search?query=2020-001588-10
https://clinicaltrials.gov/show/NCT05267392
https://clinicaltrials.gov/ct2/show/NCT02830282; https://www.cancer.gov/about-cancer/treatment/clinical-trials/search/v?id=NCI-2014-00596; https://www.ispytrials.org/i-spy-platform/substudies/i-spy2-surmount-study
https://clinicaltrials.gov/show/NCT05262985
https://clinicaltrials.gov/show/NCT05255653; https://ijgc.bmj.com/content/31/Suppl_3/A108.2
https://clinicaltrials.gov/show/NCT05253131
https://clinicaltrials.gov/show/NCT05245994
https://clinicaltrials.gov/show/NCT05239169; https://www.clinicaltrialsregister.eu/ctr-search/search?query=2021-002389-41

I need to extract words contains "NCT" and want the desire output like below

NCT05301842
NCT01564368
NCT05267392
NCT05262985
NCT05255653
NCT05253131
NCT05245994
NCT05239169

Kindly help me out folks

Thanks in advance

Upvotes: 1

Views: 29

Answers (1)

ThomasIsCoding
ThomasIsCoding

Reputation: 101099

We can use regmatch with pattern NCT\\d+, which extracts the substrings starting with NCT

regmatches(s,gregexpr("NCT\\d+",s))

Upvotes: 1

Related Questions