A.3 Greedy and lazy quantifiers

Greedy Lazy
* *?
+ +?
{n, } {n, }?

A common use case of lazy quantifiers is when we need to strip from html form text all its tags:

text <- "This offer is not available to customers living in <B>AK</B> and <B>HI</B>"

# lazy 
str_extract_all(text, "<[Bb]>.+?</[Bb]>")
#> [[1]]
#> [1] "<B>AK</B>" "<B>HI</B>"
# greedy
str_extract_all(text, "<[Bb]>.+</[Bb]>")
#> [[1]]
#> [1] "<B>AK</B> and <B>HI</B>"