在这里,我试图在字符串中找到模式的所有匹配项:
theString: "There is a blue truck and a red car next to an orange building."
thePattern: [["blue" | "red" | "orange"] ["truck" | "car" | "building"]]
print parse thePattern theString
Run Code Online (Sandbox Code Playgroud)
["red truck" "blue car" "orange building"]该parse函数返回而不是返回false.
Rebol是否有任何函数可用于查找字符串中模式的所有匹配,类似于其他编程语言的正则表达式匹配函数?
你可以试试这个:
string: "There is a blue truck and a red car next to an orange building."
pattern: [
["blue" | "red" | "orange"]
space
["truck" | "car" | "building"]
]
parse string [
some [
copy value pattern (print value)
| skip
]
]
Run Code Online (Sandbox Code Playgroud)
打印:
blue truck
red car
orange building
Run Code Online (Sandbox Code Playgroud)
skip用于在模式不匹配时移动到下一个字符.此外,还会在模式中添加空间,因为它不是"bluetruck"或"redcar".
括号用于在解析规则中执行Rebol代码,因此您可以替换print其他内容(如append block value等)
| 归档时间: |
|
| 查看次数: |
231 次 |
| 最近记录: |