Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个这样的字符串:"something_before cl: something_after"
"something_before cl: something_after"
cl:是我的标记,我想抓住它后面的每一个字。在这种情况下,我想抓住字符串"something_after"。我该怎么做?
cl:
"something_after"
目前我这样做:commit_log.scan(/cl: .*/)[0].gsub("cl: ", "")。但是这段代码很难看,我正在寻找一种更好的方法来重写它。
commit_log.scan(/cl: .*/)[0].gsub("cl: ", "")
与标记分开
"something_before cl: something_after".split("cl: ").last => "something_after"
或使用后向断言
"something_before cl: something_after".scan /(?<=cl: ).*/ => [" something_after"]