Word break problem: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: updated output, simplified regex) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: oops, missing) |
||
Line 510: | Line 510: | ||
my @matches; |
my @matches; |
||
my $one_of = join '|', @dictionary; |
my $one_of = join '|', @dictionary; |
||
@matches = $word =~ /^ ($one_of) ($one_of)? ($one_of)? ($one_of)? $/x # sub-optimal: limited number of matches |
@matches = $word =~ /^ ($one_of) ($one_of)? ($one_of)? ($one_of)? $/x; # sub-optimal: limited number of matches |
||
return join(' ', grep {$_} @matches) || "(not possible)"; |
return join(' ', grep {$_} @matches) || "(not possible)"; |
||
}</lang> |
}</lang> |