У меня есть большое количество высказываний, каждое из которых содержит слово «хорошо» в различных положениях высказывания.Вот некоторые иллюстративные данные:
data <- c("well what the church meeting 's got to decide",
"oh well yes those are those are normal things",
"well they 've sent you a letter from hospital",
"and i think well you cheeky sod you know",
"'cos she 's well that day albert took me",
"yeah well you 're going out anyway so you")
Я хотел бы извлечь те высказывания, которые удовлетворяют отрицательному позиционному критерию : это 'хорошо«не первое или второе слово в высказывании.Ожидаемый результат:
data <- c("and i think well you cheeky sod you know",
"'cos she 's well that day albert took me")
Этот шаблон заставляет меня делать то, что я делаю не хочу извлечь:
grep("^well|^\\w*\\swell", data, perl = T, value = T)
[1] "well what the church meeting 's got to decide" "oh well yes those are those are normal things"
[3] "well they 've sent you a letter from hospital" "yeah well you 're going out anyway so you"
Теперь трюк будет Отрицать этот шаблон.Я пробовал использовать отрицательный прогноз, но он не работает:
grep("(?!^well|^\\w*\\swell)", data, perl = T, value = T)
[1] "well what the church meeting 's got to decide" "oh well yes those are those are normal things"
[3] "well they 've sent you a letter from hospital" "and i think well you cheeky sod you know"
[5] "'cos she 's well that day albert took me" "yeah well you 're going out anyway so you"
Какое регулярное выражение в R будет выполнять искомое извлечение?Заранее спасибо.