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

Re: Regex to compare (if) two strings (Uniquely - I will explain inside)

by AnomalousMonk (Chancellor)
on Nov 25, 2012 at 11:53 UTC ( #1005478=note: print w/replies, xml ) Need Help??

in reply to Regex to compare (if) two strings (Uniquely - I will explain inside)

In a similar vein to this, another regex approach. I hesitate to offer it because I'm not sure the increased complexity pays off. More effort is spent in building the thing, but despite being significantly larger, the final regex may run more quickly versus the repeated compilation and invocation of the shorter  s/// of the previous link. However, it may take operation on rather long strings for any advantage to become manifest. I have done no benchmarking, but at least it's tested and works. The dreams of regexen produce monsters.

sub scrabblicious { my ($word, # word to test for proper match to tray of letters $tray, # string with 'tray' of letters to select from ) = @_; return unless # handles word empty string (my $rx = join '', sort split '', $word) =~ s{ (.) \1* } { $+[0] - $-[0] > 1 ? qq/(?= (?: .*? \Q$1\E){@{[ $+[0] - $-[0] ]}})/ : qq/(?= .*? \Q$1\E)/ }xmseg; return $tray =~ m{ \A $rx }xms; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005478]
LanX wants to ignore NodeReaper ...
[NodeReaper]: how dare you!
[choroba]: Ignoring the Reaper doesn't ensure he ignores you back
[choroba]: In Soviet Russia...
LanX is immortal! (so far ...)
Discipulus nevers ignores who is here since ever
[Eily]: IIRC 3% of all humans in history never ever died
[NodeReaper]: this is emotional, what did I do to deserve this?

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2018-03-19 10:44 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.