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 extract part from string?

If I have this string:

bb=c("\\dat\\Bjkjgf_Yloiut_dsezr_proj_111_999.txt","\\dat\\Bjkjgf_Yloezr_proj_111_999.txt")

I need to extract whatever between \\ and _proj

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

i can do this, but will work for one and not the other:

substr(bb, 1, 15)

the expected output

Bjkjgf_Yloiut_dsezr,Bjkjgf_Yloezr

>Solution :

Using gsub

gsub(".*\\\\|_proj.*", "", bb)
[1] "Bjkjgf_Yloiut_dsezr" "Bjkjgf_Yloezr"
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