Need to write an AND regex in ruby -
i need regex check if string starts "v " , if has word 'bench' or 'earcx' in it.
my current expression written as: v\s|bench|earcx
realized taking 'v ' or bench or earcx. there and condition regular expressions in ruby? if so, how can check both 'v ' , bench or earcx
any appreciated!
if order matters (as say, "starts v"), can write simply:
/v.*(bench|earcx)/ if not, can wrap in alternation:
/v.*(bench|earcx)|(bench|earcx).*v/ but getting unwieldy (especially if have several different , factors, better use lookaheads:
/(?=.*v)(?=.*(bench|earcx))/ this match vbench, earcxfoov... , solution general case , anywhere in string.
Comments
Post a Comment