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

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

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

html - jQuery UI Sortable - Remove placeholder after item is dropped -