pe icon indicating copy to clipboard operation
pe copied to clipboard

Bounded repetitions

Open goodmami opened this issue 1 year ago • 0 comments

A simple but useful extension is for bounded repetitions. The main issue is the syntax to use for it. One obvious choice is {count} or {start,end} as in regex. A counterpoint to this is that {...} is used for semantic actions by some parsing frameworks, but I don't anticipate Pe using those.

The behavior would follow regular expressions. Example:

>>> pe.match(".{1,3}", "abcdefg")
<Match object; span=(0, 3), match='abc'>
>>> pe.match(".{2}", "abcdefg")
<Match object; span=(0, 2), match='ab'>
>>> pe.match(".{2,}", "abcdefg")
<Match object; span=(0, 7), match='abcdefg'>
>>> pe.match(".{,2}", "abcdefg")
<Match object; span=(0, 2), match='ab'>

In the {start,end} case, either operand can be omitted to indicate an open range, from 0 to infinity. Thus, .{,} is equivalent to .*, and .{1,} is equivalent to .+.

goodmami avatar Jan 21 '24 22:01 goodmami