Remove/Replace/Extract Phone Numbers

Usage

rm_phone(text.var, trim = !extract, clean = TRUE, pattern = "@rm_phone", replacement = "", extract = FALSE, dictionary = getOption("regex.library"), ...)

Arguments

text.var
The text variable.
trim
logical. If TRUE removes leading and trailing white spaces.
clean
trim logical. If TRUE extra white spaces and escaped character will be removed.
pattern
A character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Default, @rm_phone uses the rm_phone regex from the regular expression dictionary from the dictionary argument.
replacement
Replacement for matched pattern.
extract
logical. If TRUE the phone numbers are extracted into a list of vectors.
dictionary
A dictionary of canned regular expressions to search within if pattern begins with "@rm_".
...
Other arguments passed to gsub.

Value

Returns a character string with phone numbers removed.

Description

Remove/replace/extract phone numbers from a string.

References

The phone regular expression was taken from: http://stackoverflow.com/a/21008254/1000343

Examples

x <- c(" Mr. Bean bought 2 tickets 2-613-213-4567 or 5555555555 call either one", "43 Butter Rd, Brossard QC K0A 3P0 - 613 213 4567", "Please contact Mr. Bean (613)2134567", "1.575.555.5555 is his #1 number", "7164347566", "I like 1234567 dogs" ) rm_phone(x)
[1] "Mr. Bean bought 2 tickets 2- or call either one" "43 Butter Rd, Brossard QC K0A 3P0 -" [3] "Please contact Mr. Bean" "is his #1 number" [5] "" "I like 1234567 dogs"
rm_phone(x, extract=TRUE)
[[1]] [1] "613-213-4567" "5555555555" [[2]] [1] "613 213 4567" [[3]] [1] "(613)2134567" [[4]] [1] "1.575.555.5555" [[5]] [1] "7164347566" [[6]] [1] NA