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_replace str_replace_all

Replace matched patterns in a string.

str_split str_split_fixed

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

Trim whitespace from start and end of 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

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_length

The length of a string.

str_interp

String interpolation.

str_replace_na

Turn NA into "NA"

str_trunc

Truncate a character string.

str_sub & -

Extract and replace substrings from a character vector.

word

Extract words from a sentence.

Bundled data

stringr-data

Sample character vectors for practicing string manipulations.