I am trying to use regular expressions to match a vector of string with all units in patterns regardless of the order in R.
mystring = c("sdxuslinafchangdfasd", "fdschangfsdahxufhglin", ",kjujudsyrg")
pattern = c("xu", "chang", "lin")
What I have in mind is:
grepl("xu", mystring) & grepl("chang", mystring) & grepl("lin", mystring)
Which could certainly get what I want. But as the number of strings in the pattern increases, the coding becomes cumbersome. I know I can use the following code if I just want to any one of the pattern, but & seems not to be working in grepl:
grepl("xu|chang|lin", mystring)
My qeustion is: Is there a fast enough and concise way to solve such a problem when the number of strings and the number of units in the pattern are large in R? The priority is speed while the secondary priority is conciseness of the codes. Thanks.