Alexandru <
alexandr...@meshparts.de> writes:
Alexandru <
alexandr...@meshparts.de> writes:
> Am Donnerstag, 14. Februar 2019 17:22:12 UTC+1 schrieb Harald Oehlmann:
>> Am 14.02.2019 um 16:47 schrieb Alexandru:
>> > I just hit the wall of max. 256 chars allowed by regexp!
>> >
>> > regexp {^(.){0,255}$} "dfsdfsdf"
>> >
>> > works!
>> >
>> > regexp {^(.){0,256}$} "dfsdfsdf"
>> >
>> > fails with:
>> >
>> > couldn't compile regular expression pattern: invalid repetition count(s)
>> >
>> > Wow! How is this possible? Next bug waiting to happen in my code all over the place.
>> >
>> [...]
>> "The forms using { and } are known as bounds. The numbers m and n are
>> unsigned decimal integers with permissible values from 0 to 255 inclusive."
>>
>> The reason is, that this format is quite expensive in evaluation.
>> If a length check should be done one should better use something else.
>> Due to that, I have implemented for input verification a descripion of 2
>> values, re and maximum length.
>>
>> proc check {s re maxlen} {
>> if {[strlen $s] > $maxlen} {return 0}
>> return [regexp -- $re $s]
>> }
>
> That's a good work arround. Thanks.
> So if the regexp would allow for longer strings that would also affect
> the performance an shorter strings?
Since nobody did so far it seems the thankless task to question your use
of regexp is left for me.
We know too less what exactly you do but since you fear bugs all over
the place it at least seems you do it a lot. Regular expressions are a
mighty tool (and often faster - sometimes a lot - than parsing a string
with other means).
On the other hand - you've surely already read or heard this at times -
using regular expressions can bear some risks. The most obvious - as
your regexps getting more complicated - is: are you always sure you
understand, what your regexp matches?
In the case at hand you bump against a regexp limit. If you are the
single one who reaches a certain limit that may (or even not, but also
even may) be a sign that you overdo something.
The point here is that - despite the ususal speed of regexps - some
regexps are ridiculous _slow_. One example is this {n,m} construct.
Since you seem to care about execution speed please measure. If you need
{0,256} or even bigger than 256 you very probably can do this another
way - eg. Haralds proposal - much faster.