Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: regex at word boundary

by davido (Cardinal)
on Dec 08, 2005 at 05:10 UTC ( [id://515131]=note: print w/replies, xml ) Need Help??


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

Regarding the length $^N > 1 test, I added that because while refining this RE I discovered that it was capable of considering a single-character string to be palindromic (new word?), since "a" in reverse is still "a".

Update: Now that I think about it, the length $^N > 1 test is better written as ..+ earlier in the RE, like this:

qr/(..+) (??{ ( lc $^N eq reverse lc $^N ) ? '' : '(?!)' }) /ix

...thus forcing at least two characters to be tested in the first place, rather than hand-coding a test for two or more characters via 'length'. Duh!


Dave

Replies are listed 'Best First'.
Re^5: regex at word boundary
by QM (Parson) on Dec 08, 2005 at 05:25 UTC
    It must be the late hour, because I missed that (.+) would give trivial palindromes of length 1.

    I prefer (.{2,}) over (..+), as those dots tend to fade into the background.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://515131]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-26 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found