glob2rx package:utils R Documentation _C_h_a_n_g_e _W_i_l_d_c_a_r_d _o_r _G_l_o_b_b_i_n_g _P_a_t_t_e_r_n _i_n_t_o _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n _D_e_s_c_r_i_p_t_i_o_n: Change _wildcard_ aka _globbing_ patterns into the corresponding regular expressions ('regexp'). _U_s_a_g_e: glob2rx(pattern, trim.head = FALSE, trim.tail = TRUE) _A_r_g_u_m_e_n_t_s: pattern: character vector trim.head: logical specifying if leading '"^.*"' should be trimmed from the result. trim.tail: logical specifying if trailing '".*$"' should be trimmed from the result. _D_e_t_a_i_l_s: This takes a wildcard as used by most shells and returns an equivalent regular expression. '?' is mapped to '.' (match a single character), '*' to '.*' (match any string, including an empty one), and the pattern is anchored (it must start at the beginning and end at the end). Optionally, the resulting regexp is simplified. Note that now even '(', '[' and '{' can be used in 'pattern', but 'glob2rx()' may not work correctly with arbitrary characters in 'pattern'. _V_a_l_u_e: A character vector of the same length as the input 'pattern' where each wildcard is translated to the corresponding regular expression. _A_u_t_h_o_r(_s): Martin Maechler, Unix/sed based version, 1991; current: 2004 _S_e_e _A_l_s_o: 'regexp' about regular expression, 'sub', etc about substitutions using regexps. _E_x_a_m_p_l_e_s: stopifnot(glob2rx("abc.*") == "^abc\\.", glob2rx("a?b.*") == "^a.b\\.", glob2rx("a?b.*", trim.tail=FALSE) == "^a.b\\..*$", glob2rx("*.doc") == "^.*\\.doc$", glob2rx("*.doc", trim.head=TRUE) == "\\.doc$", glob2rx("*.t*") == "^.*\\.t", glob2rx("*.t??") == "^.*\\.t..$", glob2rx("*[*") == "^.*\\[" )