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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -