Skip to content
Prev 371597 / 398506 Next

Searching for Enumerated Items using str_count() from the stringr package

On 09/29/2017 12:02 AM, T?th D?nes wrote:
Ah, now I see what you were after: enumerations are not in a standard 
format, so "1) " can be "1)", "1.", "1 .".

In this case:
text <- "1)Hello\n2.Hi\n3 .Cheers"
keywords <- "[0-9]+(\\)| *?\\.)"
stri_count_regex(text, keywords)

Note the '|' sign in the keyword definition. It means OR in this 
context. So literally the regexp expression above can be translated as:
A digit or a digit string followed by a parenthesis, or by arbitrary 
number of spaces (even 0) before a dot.

HTH,
Denes