Test Regular Expression Validity

Usage

is.regex(pattern)

Arguments

pattern
A regular expression to be tested.

Value

Returns a logical (TRUE is a valid regular expression).

Description

Acts as a logical test of a regular expression's validity. is.regex uses gsub and tests for errors to determine a regular expression's validity. The regular expression must conform to R's regular expression rules (see ?regex for details about how R handles regular expressions).

Examples

is.regex("I|***")
[1] FALSE
is.regex("I|i")
[1] TRUE
sapply(regex_usa, is.regex)
rm_abbreviation rm_between rm_between2 rm_caps rm_caps_phrase TRUE TRUE TRUE TRUE TRUE rm_citation rm_citation2 rm_citation3 rm_citation_tex rm_city_state FALSE TRUE FALSE TRUE TRUE rm_city_state_zip rm_date rm_date2 rm_date3 rm_date4 TRUE TRUE TRUE TRUE TRUE rm_dollar rm_email rm_emoticon rm_endmark rm_endmark2 TRUE TRUE TRUE TRUE TRUE rm_endmark3 rm_hash rm_nchar_words rm_nchar_words2 rm_non_ascii TRUE TRUE TRUE TRUE TRUE rm_non_words rm_number rm_percent rm_phone rm_postal_code TRUE TRUE TRUE TRUE TRUE rm_repeated_characters rm_repeated_phrases rm_repeated_words rm_tag rm_tag2 TRUE TRUE TRUE TRUE TRUE rm_title_name rm_time rm_time2 rm_transcript_time rm_twitter_url TRUE TRUE TRUE TRUE TRUE rm_url rm_url2 rm_url3 rm_white rm_white_bracket TRUE TRUE TRUE TRUE TRUE rm_white_colon rm_white_comma rm_white_endmark rm_white_lead rm_white_lead_trail TRUE TRUE TRUE TRUE TRUE rm_white_multiple rm_white_punctuation rm_white_trail rm_zip TRUE TRUE TRUE TRUE
sapply(regex_supplement, is.regex) ## `version` is not a valid regex
after_a after_the after_ around_ around2_ before_ TRUE TRUE TRUE TRUE TRUE TRUE except_first hexadecimal ip_address last_occurrence pages pages2 TRUE TRUE TRUE TRUE TRUE TRUE punctuation run_split split_keep_delim thousands_separator time_12_hours version TRUE TRUE TRUE TRUE TRUE FALSE version2 white_after_comma word_boundary word_boundary_left word_boundary_right youtube_id TRUE TRUE TRUE TRUE TRUE TRUE

See also

gsub