in reply to Re: regex at word boundary
in thread regex at word boundary

You're right, the (corrected) code won't find palindromes. It wasn't intended to. It was the first step in finding a palindrome candidate. After the candidate is found I can strip out spaces and check to see if the word group does qualify as a palindrome.

Ultimately I don't care about finding palindromes. It is just a little puzzle to apply some time to. Some people do soduko puzzles, some crosswords, I look for little problems that I don't know the answer to and explore the possibilities.

Be Appropriate && Follow Your Curiosity

Replies are listed 'Best First'.
Re^3: regex at word boundary
by QM (Parson) on Dec 07, 2005 at 21:07 UTC
    You're right, the (corrected) code won't find palindromes. It wasn't intended to. It was the first step in finding a palindrome candidate.
    OK, fair enough. So what did you want it to do? Did you just want to check for repeated characters at the proper end of word boundaries?

    [Insert "Lightbulb Over Head" graphic here ]

    You just want a filter to grab candidates, then strip whitespace, then test for palindrome-ness.

    I think you'd do us a favor by coming up with an appropriate regex with ??{code}, something near:

    /(\b (([a-z]) # at least one char ?{local @suffix; push @suffix, $^N}) # build up suffix (([a-z) ?{local @suffix; push @suffix, $^N} | \S+)+ [a-z]? # possible odd char (([a-z]) (?{if ($^N eq $suffix[-1]) {pop @suffix}}) | \S+)+) (([a-z]) (?{if ($^N eq $suffix[-1]) {pop @suffix}}) \b) /x
    Though I don't think that works, and it's untested. (Hey, I have to leave something up to you.) Besides, there's a lot left out of the perlre with ?{code} and ??{code}, so please come back and tell us what it should say :)

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of