From: Eric Luo Date: 2005-07-03T23:37:50+09:00 Subject: Re: Ask for help about Regexp ------=_Part_9988_11893867.1120401467635 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Yes, It's really what I want.=20 Seem to be a little diffcult to resolve the problem properly. I had to work around my biz requirement 'cause I cound't manage to do with it Thank you for your help On 7/1/05, Daniel Brockman wrote: >=20 > Nikolai Weibull writes: >=20 > > Eric Luo wrote: > > > >> I need to match my input dynamically by Regexp, For example: I want > >> match to this regexp: mask =3D /\d{10}tt\d{0, 5} then I give my input > >> byte by byte. And I want to be noticed at the first time when it is > >> impossible for me to match my input to the regexp mask. so if i input > >> 34789d, when I the input the character 'd', I will be noticed. > >> > >> I wonder if it's possible or not. if it is, how could I do that? > > > > Well, you can't easily do that. You could write a regex that matches > > valid prefixes of the strings of the language of the final regex, but > > that can become quite complicated. You should probably rethink your > > algorithm, >=20 > Nikolai is right: you can't easily do that. But I think it would be > easy to modify the regular expression engine to make it possible. > Unless I am mistaken, the only information you need is whether or not > the engine ever wanted to look past the end of the input string. >=20 > If the engine ever managed to consume all characters and still be > hungry for more, then your string is a valid prefix. Conversely, if > the engine did not do this, then your string is not a valid prefix. > Note that merely consuming all characters is not sufficient; the match > has to fail due to lack of additional input. >=20 > I just posted about this on Perl Monks, >=20 > >=20 > so consider following up there if you have anything to add. >=20 > I don't feel like hacking this into regex.c right now, and I'm not > sure what the API should be like. >=20 > But I do think it would be a useful feature. The fact that noone > seems to have wanted it before baffles me. Perhaps up until now, > noone even considered the possibility. >=20 > -- > Daniel Brockman >=20 >=20 > ------=_Part_9988_11893867.1120401467635--