ruby if string contains -
with following code, expect bravo if file name 123456.txt.
if file_name#=~ ('.+(775|776|777|778)\.txt') @outputs['answer'] = 'alpha' elsif file_name#=~ (.+(456|546)\.txt) @outputs['answer'] = 'bravo' but answer results in alpha. missing here?
# defines start of comment. operator test against regexes =~, not #=~.
if file_name will case being picked, unless file_name false or nil, hence why 'alpha'.
also literal syntax create regexes //, not (''):
if file_name =~ /.+(775|776|777|778)\.txt/
Comments
Post a Comment