in reply to Re: Conditional regex
in thread Conditional regex

/^(\w+)\1|(\w+)(\w+)\3\2$/ matches ssaa.

Abigail

Replies are listed 'Best First'.
Re: Re: Conditional regex
by Roger (Parson) on Jan 12, 2004 at 12:57 UTC
    But I thought 'ssaa' matches the '$x$y' pattern, where $x is 'ss' and $y is 'aa', that still fits the requirement?

    Thanks Abigail-II, I have realized my mistake. Here's an updated version that works -
    #!/usr/local/bin/perl -w use strict; my @words = qw/ beriberi coco couscous deed toot toto tutu assa ssaa /; for (@words) { print "$_\n" if /^(\w+)\1$/ || /^(\w+)(\w+)\2\1$/; }

    And output -
    beriberi coco couscous deed toot toto tutu assa

      Oh, in that case, /^(\w+)\1|(\w+)(\w+)\3\2$/ doesn't match saaa which is part of your own test case. You know, just pick $x = "sa" and $y = "aa", so it matches this new "$x$y" requirement.

      Don't you read your own comments? "$x$x" or "$x$y$y$x". Not "$x$y", which could be matched by /^\w{2,}$/.

      Abigail