1
我没有在Python如下:我怎样才能拆分字符串并保留空格呢?
s = 'This is a text'
re.split('(\W)', s)
# => ['This', ' ', 'is', ' ', 'a', 'text']
它的工作好了。我如何在Ruby中进行相同的拆分?
我已经试过这一点,但它吃了我的空白:
s = "This is a text"
s.split(/[\W]/)
# => ["This", "is", "a", "text"]