У меня есть очень длинная строка, как этот пример ниже, и я изо всех сил пытаюсь найти регулярное выражение, чтобы разделить его на части в соответствии с паттерном, например: '1.OAS / AC 'и' 2.OAS / AD '.
Этот фрагмент текста имеет:
1) различное число в начале
2) две заглавные буквы от A до Z
Я пробовал это:
x <- stringr::str_split(have, "([1-9])( OAS / )([A-Z]{2})")
но не работает
Заранее спасибо за любую помощь!
Пример
require(stringr)
have <- "1. OAS / AC 12345/this is a test string to regex, 2. OAS / AD 79856/this is another test string to regex, 3. OAS / AE 87987/this is a new test string to regex. 4. OAS / AZ 78798456/this is one mode test string to regex."
want <- stringr::str_split(have, "([1-9])( OAS / )([A-Z]{2})")
want <- list(
"1. OAS / AC " = "12345/this is a test string to regex,",
"2. OAS / AD " = "79856/this is another test string to regex,",
"3. OAS / AE " = "87987/this is a new test string to regex.",
"4. OAS / AZ " = "78798456/this is one mode test string to regex."
)