Well George I came up with the same number of 'patterns' but I didnt need a regex. I thought you might like to see it:
my $s='helloworldhellohellohihellohiworld';
#determine every substring in the original
my %hash;
for my $i (0..length($s)-1) {
$hash{substr($s,$i,$_)}++
for (1..length($s)-$i);
}
#filter out singles and the chars
%hash=map {
($hash{$_}>1 && length($_)>1)
? ($_,$hash{$_})
:()
} keys %hash; #yes this is how i format maps
#and ternary ops.. :-)
#print the results
use Data::Dumper;
print Dumper(\%hash);
Id love to know how the OP wanted the computer to tell that 'hello' is a word but 'elloh' isnt... (forgetting real english words that are embedded like 'low' 'el' 'hell')
Incidentally get the following results (reformatted):
el,ell,ello,elloh,ellohi,
he,hel,hell,hello,helloh,hellohi,hi,
ld,ll,llo,lloh,llohi,lo,loh,lohi,
oh,ohi,or,orl,orld,
rl,rld,wo,wor,worl,world
I have a feeling there isn't really a way to do what the OP wants to do. Its not really prefix matching, nor suffix matching....
To the OP what should happen here if said 7 words?
'hellohiothellobrakerakerashash'
Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)
Update minor bugfixes and challenge to Op
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.