通过多个分隔符拆分字符串 [英] Split string by multiple delimiters
本文介绍了通过多个分隔符拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用单个 ruby 命令按空格、、
和 '
拆分字符串.
I want to split a string by whitespaces, ,
and '
using a single ruby command.
word.split
将被空格分割;
word.split(",")
将被 ,
分割;
word.split("\'")
将被 '
分割.
如何同时做这三件事?
推荐答案
word = "Now is the,time for'all good people"
word.split(/[\s,']/)
=> ["Now", "is", "the", "time", "for", "all", "good", "people"]
这篇关于通过多个分隔符拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文