你有一个'通过太多。
red>> parse %abc/file.ext [collect[keep [some [thru #"/"] | keep (none) ] keep to end]]
== [%abc/ %file.ext]
red>> parse %/abc/file.ext [collect[keep [some [thru #"/"] | keep (none) ] keep to end]]
== [%/abc/ %file.ext]
red>> parse %/abc/def/file.ext [collect[keep [some [thru #"/"] | keep (none) ] keep to end]]
== [%/abc/def/ %file.ext]
如果输入中没有斜线,我正在使用'some,因此规则失败。然后使用“| keep (none)”保留你想要的'none。
“keep(something)”通过'do方言保持运行“something”的返回值。
red>> parse %file.ext [collect[keep [some [thru #"/"] | keep (none) ] keep to end]]
== [none %file.ext]
没有它,你只会得到文件部分。
red>> parse %file.ext [collect[keep [any [thru #"/"]] keep to end]]
== [%file.ext]
red>> parse %/abc/def/file.ext [collect[keep [any [thru #"/"]] keep to end]]
== [%/abc/def/ %file.ext]