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

String after and before character

I have this string

x = "Hello   how are    you Peter /"

And I would like to get only

x = "Peter"

I would like to find patter that extract only word after "you" and before "/" (exluded)

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 would like to use something like

x = sub(" you*/.", "", x)

But I dont know how to make the pattern correctly.

>Solution :

library(stringr)
str_match(x, "you\\s*(.*?)\\s*\\/")[, 2]
#[1] "Peter"
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