Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Re: Re: Pattern Finding

by runrig (Abbot)
on Sep 11, 2001 at 20:14 UTC ( #111770=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Patter Finding
in thread Pattern Finding

I would expect any of the following: hello,hi,othello,brake,rake,raker,rash,ash,hash,ohio, the,lob,bra,hell,era

I don't see how you could expect some of those strings, because some only appear once in the string (e.g. "othello", "ohio"), so you really couldn't call them a "pattern" unless you're matching against a dictionary file.

My solution near the top of this thread sort of assumes that the string is a contiguous series of patterns (one of the original constraints was "String contains nothing but patterns"), so it only finds "hello" from your test string, but if you change this line:

# From this if (/\G(.{2,})(?=.*?\1)/g) { # To this if (/\G.*?(.{2,})(?=.*?\1)/g) {
Then it does better and finds "ash", "rake", and "hello" from your test string, which is about as good as it gets, I believe.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://111770]
[Corion]: erix: Heh ;) Transcribing/ writing notes is a good thing, at least for the stuff out of copyright!

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-06-24 07:33 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.