Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Regular Expression Builder

by tommyw (Hermit)
on Aug 30, 2002 at 15:36 UTC ( #194145=note: print w/replies, xml ) Need Help??

in reply to Regular Expression Builder

Programming Perl includes:

#!/usr/bin/perl $vowels='aeiouy'; $cons='bcdfghjklmnpqrstvwxzy'; %map={C=>$cons, V=>$vowels; for $class=($vowels, $cons) { for (split //, $class) { map{$_}.=$class; } } for $char (split //, shift) { $pat.="[$map{$char}]"; } $re=qr/^${pat}$/i; print "REGEX is $re\n"; @ARGV='/usr/dict/words' if -t && !@ARGV; while (<>) { print if /$re/; }
Which takes a word, and builds a template from it with the same pattern of vowels and consonants. Although the original is commented. Extending this to handle digits should be easy. The cunning part will be collapsing the multiple character classes down, and using a multiple instead.

This is, of course, left as an exercise for the reader ;-)

Too stupid to live.
Too stubborn to die.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194145]
[LanX]: Sinai_Peninsula
[robby_dobby]: choroba: If you're talking of Eurasia, it's only true of the erstwhile Constantinople/ Ottoman empire
[LanX]: yes correct, but Sinai is not on the other side
[LanX]: Organizing a YAPC in a tourist ressort is not a bad idea ...
[LanX]: ... and we could swap to our first YAPC Africa the following year when organizing in Hurghada
[robby_dobby]: LanX: Well volunteered!
[LanX]: ... just ... ppl would be to afraid of terrorist attacks
[choroba]: python guerrila?
[robby_dobby]: if I do make it, I can at least savour their local tea! :-)
[LanX]: oh they have sleper cells everywhere

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (15)
As of 2017-04-24 16:07 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.