Pattern matching

str_count()

Count the number of matches in a string

str_detect()

Detect the presence or absence of a pattern in a string

str_extract() str_extract_all()

Extract matching patterns from a string

str_locate() str_locate_all()

Locate the position of patterns in a string

str_match() str_match_all()

Extract matched groups from a string

str_remove() str_remove_all()

Remove matched patterns in a string

str_replace() str_replace_all()

Replace matched patterns in a string

str_starts() str_ends()

Detect the presence or absence of a pattern at the beginning or end of a string.

str_split() str_split_fixed() str_split_n()

Split up a string into pieces

str_subset() str_which()

Keep strings matching a pattern, or find positions

str_view() str_view_all()

View HTML rendering of regular expression match

fixed() coll() regex() boundary()

Control matching behaviour with modifier functions

Whitespace

str_pad()

Pad a string

str_trim() str_squish()

Trim whitespace from a string

str_wrap()

Wrap strings into nicely formatted paragraphs

Locale senstive

str_order() str_sort()

Order or sort a character vector

str_to_upper() str_to_lower() str_to_title() str_to_sentence()

Convert case of a string

Other helpers

invert_match()

Switch location of matches to location of non-matches.

str_c()

Join multiple strings into a single string

str_conv()

Specify the encoding of a string

str_dup()

Duplicate and concatenate strings within a character vector

str_flatten()

Flatten a string

str_glue() str_glue_data()

Format and interpolate a string with glue

str_length()

The length of a string

str_replace_na()

Turn NA into "NA"

str_trunc()

Truncate a character string

str_sub() `str_sub<-`()

Extract and replace substrings from a character vector

word()

Extract words from a sentence

Bundled data

sentences fruit words

Sample character vectors for practicing string manipulations