I want to parse a string to find the first N duplicate characters found in the set (character, n).
For example, for "ozzllluu"and sets ("u" => 2), ("d" => 2), ("l" => 3) and ("r" => 3) .. I would like to find "lll", because it is 3 characters and occurs up to two "u" s.
procedural style:
Rebol []
seq-set: [#"u" 2 #"d" 2 #"l" 3 #"r" 3]
str: "ozzllluu"
lastchar: ""
cnt: 1
seq-char: ""
foreach char str [
either char = lastchar [
cnt: cnt + 1
if (select seq-set char) = cnt [
seq-char: char
break
]
][
cnt: 1
]
lastchar: char
]
either seq-char = "" [
print "no seq-char"
][
print join "seq-char " seq-char
]
How can I do the same with a rule parse?
In short:
parse a string for the first n repeating character found in (character, n) set- "function" existing procedural code
- dogfood in Rebol / Red!