How to convert a glob with braces to a regex -
i want change glob such c{at,lif} in regex. like? i've tried using /c[at,lif]/ did not work.
for basic grep operation see f.e. http://www.regular-expressions.info/refquick.html
from http://www.regular-expressions.info/alternation.html:
if want search literal text cat or dog, separate both options vertical bar or pipe symbol: cat|dog. if want more options, expand list: cat|dog|mouse|fish.
this suggests following should work:
/c(at|lif)/
obligatory wrong yours, then:
/c[at,lif]/
the square brackets [..]
not used in grep grouping, define character class. is, here create custom class allows 1 of characters at,lif
. matches ca
or c,
or cf
-- 1 character. adding repetition code c[at,lif]+
appears work because match both cat
, clif
, cilt
, calf
, , c,a,t
.
Comments
Post a Comment