| str_extract_non_numerics {strex} | R Documentation |
str_extract_non_numerics extracts the bits of the string that aren't
extracted by extract_numbers. str_nth_non_numeric is a convenient wrapper
for str_extract_non_numerics, allowing you to choose which number you want.
Please run the examples at the bottom of this page to ensure that you
understand how these functions work, and their limitations. These functions
are vectorized over string.
str_extract_non_numerics(string, decimals = FALSE, leading_decimals = FALSE, negs = FALSE) str_nth_non_numeric(string, n, decimals = FALSE, leading_decimals = FALSE, negs = FALSE) str_first_non_numeric(string, decimals = FALSE, leading_decimals = FALSE, negs = FALSE) str_last_non_numeric(string, decimals = FALSE, leading_decimals = FALSE, negs = FALSE)
string |
A string. |
decimals |
Do you want to include the possibility of decimal numbers
( |
leading_decimals |
Do you want to allow a leading decimal point to be the start of a number? |
negs |
Do you want to allow negative numbers? Note that double negatives are not handled here (see the examples). |
n |
The index of the number (or non-numeric) that you seek. Negative
indexing is allowed i.e. |
str_first_non_numeric(...) is just
str_nth_non_numeric(..., n = 1).
str_last_non_numeric(...) is just
str_nth_non_numeric(..., n = -1).
str_extract_non_numerics("abc123abc456")
str_extract_non_numerics("abc1.23abc456")
str_extract_non_numerics("abc1.23abc456", decimals = TRUE)
str_extract_non_numerics("abc1..23abc456", decimals = TRUE)
str_extract_non_numerics("abc1..23abc456", decimals = TRUE,
leading_decimals = TRUE)
str_extract_non_numerics(c("-123abc456", "ab1c"))
str_extract_non_numerics("-123abc456", negs = TRUE)
str_extract_non_numerics("--123abc456", negs = TRUE)
str_extract_non_numerics("--123abc456", negs = TRUE)
str_nth_non_numeric("--123abc456", 1)
str_nth_non_numeric("--123abc456", -2)