gpt4 book ai didi

regex - clojure regex 来匹配单词和介于两者之间的所有内容

转载 作者:行者123 更新时间:2023-12-04 04:43:33 26 4
gpt4 key购买 nike

这比 Clojure 更像是一个正则表达式问题,但我正在 Clojure 中测试它。

(re-seq #"\w+" "This is a test. Only a test!")

产生:
("This" "is" "a" "test" "Only" "a" "test")

我想要这个:
("This" " " "is" " " "a" "test" ". " "Only" " " "a" " " "test" "!")

我得到所有单词的地方,但单词之间的所有其他内容也包括在内。
如果它们是分开的,我不在乎时间和空间 "." " "或一起“。”

这对正则表达式很简单吗?

最佳答案

尝试使用以下正则表达式:

\w+|\W+

> (re-seq #"\w+|\W+" "This is a test. Only a test!")
("This" " " "is" " " "a" " " "test" ". " "Only" " " "a" " " "test" "!")

关于regex - clojure regex 来匹配单词和介于两者之间的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18551727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com