in reply to string containing characters
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11163777 use warnings; my @wanted = (1, 2, 3, 4); my $pattern = join '', map "(?=.*\Q$_\E)", @wanted; for my $test ('1432', '1345', 'brown fox', '9876?54321') { printf "%20s => %s\n", $test, $test =~ /^$pattern/s ? "has all" : "does not have all"; }
Outputs:
1432 => has all 1345 => does not have all brown fox => does not have all 9876?54321 => has all
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: string containing characters
by ikegami (Patriarch) on Jan 21, 2025 at 22:47 UTC |