String tip: complex pattern recognition

By Deependra Dhakal in R

December 22, 2018

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"
Posted on:
December 22, 2018
Length:
1 minute read, 44 words
Categories:
R
Tags:
R tidyverse
See Also:
Simulating genetic drift
Missing negative from the normal
Internals of Mixed Models