String tip: complex pattern recognition

Background

This post is all about examples and use cases. So…Let’s break a leg.

  1. Extract all words except last one using anchors and look arounds
nasty_char <- c("I love playing wildly")  # remove the last word 'wildly'

stringr::str_extract(nasty_char, ".*(?=\\s[:alpha:]*$)")
## [1] "I love playing"
comments powered by Disqus

Related