nitely / nim-regex

Pure Nim regex engine. Guarantees linear time matching
https://nitely.github.io/nim-regex/
MIT License
228 stars 21 forks source link

need a way to match at beginning of string when start > 0 #80

Open timotheecour opened 4 years ago

timotheecour commented 4 years ago

following https://github.com/nitely/nim-regex/pull/67, ^ now refers to position 0 (instead of start) even if start > 0. We need a way to allow matching at position = start (ie emulate the behavior of ^ before https://github.com/nitely/nim-regex/pull/67).

As suggested here https://github.com/nitely/nim-regex/issues/64#issuecomment-622289959, how about adding a bool flag, treatStartAsStart, with perhaps a better name?

note

nitely commented 4 years ago

What about passing a slice? or an openArray?

IIRC, match behaves differently from find for ^ when start > 0

Yeah, it does. Maybe it needs fixing.

timotheecour commented 4 years ago

What about passing a slice? or an openArray?

that would prevent using context eg lookaround: (?=T|^S)suffi note that this currently gives Invalid lookaround, expected closing symbol. Beware lookaround is currently limited to match one single character but that's a limitation that (hopefully) will be lifted in the future (as in D's regex + other libs), so openArray would not help there.

Note that supporting openArray is independently useful.

nitely commented 4 years ago

Oh, a special case. I'll wait for re/nre to implement it anyway.

btw, is there a regex engine that has this feature? I tried Python's re, but it works just like re/nre.

timotheecour commented 4 years ago

I'm not sure; but supporting openArray would indeed help in the meantime

auxym commented 1 year ago

I think this would be a useful feature (allowing ^ to match at position start instead of fixed 0), whether as default behavior or with a flag.

Edit: Or alternatively, find/match procs that accept openArray[char] for the input string.