In article <slrnbptabt.gh9.Belial@carbon.redbrick.dcu.ie>,
David Gillen <Belial@RedBrick.DCU.IE> wrote:
[color=blue]
> An noise sounding like Daniel Tryba said:[color=green]
> > Albert <albert@arbel-designs.com> wrote:[color=darkred]
> >> I am writing an elearning software with php. I need a script to
> >> recognize any inut of the type ab,aabb,aaabbb,aaaabbbb..... And so on.
> >> Could anyone tell me how can I do this using regular expressions?[/color]
> >
> > So basically you need a regexp tutorial. I don't know any but studing
> >
http://nl.php.net/manual/en/pcre.pattern.syntax.php might help.
> >
> > But what you want is trivial:
> >
> > /a+b+/
> >
> > a+ means: 'a' one or more times.
> > a+b+ means: 'a' one or more times followed by 'b' one or more times.
> >[/color]
> His problem was trivial, unfortunately you weren't able to see what he
> required. The solution isn't quite as trivial.
> Your solution would allow something along the lines of abbbb. What was asked
> for was the same number of a's and b's.[/color]
Yes, he needs a *script* to accomplish that. It doesn't sound like there's
any requirement for the entire solution to be contained within the
regex[*]. A capturing regex takes care of the script's first step. Then
the script can easily be finished with a strlen operation.
Daniel, see
http://php.net/pcre.pattern.syntax and
http://php.net/strlen for more info.
* Though if there were such an arbitrary requirement, one could do the
length check within the callback function for preg_replace_callback and
then return a boolean as the replace value. A silly workaround, but one
that arguably meets such a requirement...
--
CC