在不同的换行符上拆分 [英] Split on different newlines
本文介绍了在不同的换行符上拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我正在对字符串执行split
,并假设来自用户的换行符是\r\n
,如下所示:
Right now I'm doing a split
on a string and assuming that the newline from the user is \r\n
like so:
string.split(/\r\n/)
我想在\r\n
或\n
上拆分.
那么正则表达式将如何拆分其中的两个?
So how what would the regex be to split on either of those?
推荐答案
您尝试过/\r?\n/
吗? ?
使\r
为可选.
Did you try /\r?\n/
? The ?
makes the \r
optional.
用法示例: http://rubular.com/r/1ZuihD0YfF
这篇关于在不同的换行符上拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文