Если вы хотите использовать для этого регулярное выражение, вы можете использовать stringr::str_extract_all
;
text <- "HARPER'S [Day 1, 9:00 A.M.]: When the computer was young, the word hacking was used to describe the work of brilliant students who explored and expanded the uses to which this new technology might be employed. There was even talk of a \"hacker ethic.\" Somehow, in the succeeding years, the word has taken on dark connotations, suggestion the actions of a criminal. What is the hacker ethic, and does it survive?"
stringr::str_extract_all(text, "^([A-Z]+'*[A-Z]*)|(\\[.*\\])|(:.*)")
[[1]]
[1] "HARPER'S"
[2] "[Day 1, 9:00 A.M.]"
[3] ": When the computer was young, the word hacking was used to describe the work of brilliant students who explored and expanded the uses to which this new technology might be employed. There was even talk of a \"hacker ethic.\" Somehow, in the succeeding years, the word has taken on dark connotations, suggestion the actions of a criminal. What is the hacker ethic, and does it survive?"
^([A-Z]+'*[A-Z]*)|(\\[.*\\])|(:.*)
, можно разбить на 3 части, разделенные оператором "или" |
.
Первые ([A-Z]+'*[A-Z]*)
говорят о поиске группы из одной или нескольких заглавных букв, за которыми следует 0 или более '
, за которыми следуют 0 или более заглавных букв.^
указывает, что это должно быть начало строки.
Второй (\\[.*\\])
говорит, что ищет группу, содержащую 0 или более элементов (.
), заключенных в квадратные скобки.
Третий (:.*)
говорит, что ищите :
, за которым следует 0 или больше чего-либо (.
)