Reputation: 391
Is it possible to use regex in spite of the newline character \n
e.g. this code works well
> "|text|".gsub(/\|(.+?)\|/){"###"}
=> "###"
this doesn't
> "|\n text|".gsub(/\|(.+?)\|/){"###"}
=> "|\n text|"
Upvotes: 1
Views: 131
Reputation: 5268
Here is an alternative to the m modifier (specific to your case):
"|\n text|".gsub(/\|([^\|]+?)\|/){"###"}
It will match until the next |
.
Upvotes: 1
Reputation: 31077
Use the m modifier for multiline matches:
"|\n text|".gsub(/\|(.+?)\|/m){"###"}
Upvotes: 3