[英]Ruby split a string using two different delimiters
I want to split a string using "+" or "-" as delimiter. 我想使用“ +”或“-”作为分隔符来分割字符串。
test.split(/-/)
will split by "-". test.split(/-/)
将被“-”分隔。 test.split(/\\+/)
will split by "+". test.split(/\\+/)
将被“ +”分隔。 I need to check for both of them. 我需要检查两个。
只需使用一个字符类,然后在其中添加+
和-
。
puts test.split(/[+-]/);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.