r - How to make glob2rx not add "^" to beginning of regex? -


i using glob2rx convert user input regular expressions match text patterns.

if user inputs run* , match runs running.

glob2rx works in constructing regex, adds ^ beginning of regex, i.e. match items @ beginning of string. however, match tokens within string well. instance, in example below, not match i running, running i returns regex pattern ^run - create run.

regex = glob2rx("run*")  (t in c("running i", "i running")) {   print (grep(regex, t)) } 

is there easy way make work?

thanks!

you can strip off initial ^ gsub:

gsub("^\\^", "", glob2rx("run*")) 

but glob2rx designed specific kind of input (file path "globs"), there may other issues pop because function designed input.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -