[英]How can I change one or more line breaks to something in ruby?
How can I change one or more line breaks to something in ruby?如何在 ruby 中更改一个或多个换行符?
article.content.gsub(/\n/, "<br />")
above code will change every 1 line break to <br />
tag, however, I want to change one or more \n to <br />
tag.上面的代码将每 1 个换行符更改为<br />
标签,但是,我想将一个或多个 \n 更改为<br />
标签。 In that way, continuous line breaks with empty lines will be substitued into a single <br />
tag.这样,带有空行的连续换行符将被替换为单个<br />
标记。 How can I do that?我怎样才能做到这一点?
Are you looking for this?你在找这个吗?
article.content.gsub(/\n+/, "<br />")
Note the plus sign after the \n
.注意\n
后面的加号。 That will change any sequence of one or more newlines to a single <br>
.这会将一个或多个换行符的任何序列更改为单个<br>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.