[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ask for help about Regexp

Eric Luo

6/28/2005 2:11:00 PM

4 Answers

Nikolai Weibull

6/28/2005 3:09:00 PM

0

Eric Luo wrote:

> I need to match my input dynamically by Regexp, For example: I want
> match to this regexp: mask = /\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,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Eric Luo

6/29/2005 12:58:00 AM

0

I want a GUI interface. when i give my input one by one. and I will get an
error message
if what I input is not compatible with my expected mask.
I had tried to google the solution for this, but I find nothing.
Would you please to give me any solutuion or clue.
Thanks

On 6/28/05, Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org>
wrote:
>
> Eric Luo wrote:
>
> > I need to match my input dynamically by Regexp, For example: I want
> > match to this regexp: mask = /\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,
> nikolai
>
> --
> Nikolai Weibull: now available free of charge at http:/...!
> Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
> main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
>
>

Daniel Brockman

7/1/2005 8:23:00 AM

0

Eric Luo

7/3/2005 2:38:00 PM

0

Yes, It's really what I want.
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 <daniel@brockman.se> wrote:
>
> Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:
>
> > Eric Luo wrote:
> >
> >> I need to match my input dynamically by Regexp, For example: I want
> >> match to this regexp: mask = /\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,
>
> 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.
>
> 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.
>
> I just posted about this on Perl Monks,
>
> <http://perlmonks.org/index.pl?node_id=...
>
> so consider following up there if you have anything to add.
>
> I don't feel like hacking this into regex.c right now, and I'm not
> sure what the API should be like.
>
> 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.
>
> --
> Daniel Brockman <daniel@brockman.se>
>
>
>