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

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -