Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Words, no consecutive doubled letters but repeated letters (updated x2)

by AnomalousMonk (Archbishop)
on Oct 27, 2022 at 20:41 UTC ( [id://11147757]=note: print w/replies, xml ) Need Help??


in reply to Words, no consecutive doubled letters but repeated letters

/\A (?= [[:alpha:]]{12} \Z) (?! .* (.) \g-1) (?= .* (.) .+ \g-1)/x and print

But if you're scanning a dictionary, don't you know to begin with that all the words are words? It might be faster to scan with
    /\A (?= .{12} \Z) (?! .* (.) \g-1) (?= .* (.) .+ \g-1)/x and print
(OTOH, I know that some dictionaries include apostrophized and hyphenated words, so maybe you need to be specific. (Update: Upon further investigation, I find that the dictionary file I'm using does, indeed, include words like "wristwatch's", so [[:alpha:]]{12} vs. .{12} makes a difference for me.))

Update 1: Note that the regexes above need Perl version 5.10+ to support the \g{n} backreference operator.

Update 2: I second GrandFather's point about splitting up the components of a complex filter regex into individual regexes: they become simpler and easier to understand and manage, In that vein:

c:\@Work\Perl>perl -wMstrict -n -le "BEGIN { $::n = 0 } /\A .{12} \z/x && !/(.) \g-1/x && /(.) .+ \g-1/x and ++$::n and print; END { print \"$::n found\" } " ..\moby\mwords\354984si.ngl
(All the stuff with $::n is for development/debug only; it can be discarded for end use.)


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found