ruby - Why doesn't ---.*--- select everything between --- inclusive? -
i have text file looks this:
some text here. text not replaced. --- , wild block appears! has stuff in i'm trying replace. --- block no more. nothing replace here. and i'd replace between --- , ---. i'm trying:
text=file.open('myfile') text.sub(/---.*---/, 'replacement') but doesn't seem work. doing wrong?
you need specify "multiline" option in pattern make dot symbol match newline characters:
thus, code should like
text.sub(/---.*?---/m, 'replacement') see example
Comments
Post a Comment