Here is my data, a string:
data <- "Mr. NAME. Content1.Mrs. NAMEE. Content2.Ms. NAME ABCD. Content3."
I get a vector of names by the syntax below:
name <- unlist(str_extract_all( text, "Mr\\.\\s[:upper:]{1,20}\\s?[:upper:]{1,20}\\.|Ms\\.\\s[:upper:]{1,20}\\s?[:upper:]{1,20}\\.|Mrs\\.\\s[:upper:]{1,20}\\s?[:upper:]{1,20}\\." ))
I get what I want:
name [1] "Mr. BOOKER." "Mr. COMER." "Mr. BAIRD." "Mrs. KIRKPATRICK."
[5] "Ms. CORTEZ MASTO." "Ms. ROSEN." "Mrs. HAYES." "Ms. SHALALA."
[9] "Mr. DEUTCH." "Mr. KENNEDY." "Mr. KRISHNAMOORTHI." "Mr. SOTO."
[13] "Mr. SOTO." "Mrs. DEMINGS." "Mr. SOTO." "Mr. CICILLINE."
[17] "Mr. SOTO." "Ms. WASSERMAN SCHULTZ." "Mr. SOTO." "Ms. WASSERMAN SCHULTZ."
How can I get a vector of the content between the names. I want a vector like this:
"Content1." "Content2." "Content3."
I tried str_subset and strsplit to get the content between the pattern that I define in str_extract function, failed again and again......