Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

String<- "46,XX,t(1;19)(p32;q13.3),t(6;9)(p22;q34),del(32)t(12;16)(p12;q21)[cp20]"

I want to extract the value: t(1;19)(p32;q13.3), t(6;9)(p22;q34), t(12;16)(p12;q21)

The regex I'm using

ABC<-str_extract(String, regex("t.{1,16}"))

The output that I get:

 t(1;19)(p32;q13.3v

1 Answer

0 votes
by (108k points)

Let us say the string looks like :

String<- "46,XX,t(1;19)(p32;q13.3),t(6;9)(p22;q34),del(32)t(12;16)(p12;q21)[cp20]"

Then you can use str_extract_all as :

stringr::str_extract_all(String, "t\\(.*?\\)\\(.*?\\)")[[1]]

#[1] "t(1;19)(p32;q13.3)" "t(6;9)(p22;q34)"    "t(12;16)(p12;q21)" 

This returns "t" followed by everything in round brackets (()), followed by everything in another round bracket next to it.

If you are a beginner in R and want to know more about R then do check out the R programming tutorial.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...