Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created March 31, 2011 02:15
Show Gist options
  • Save aanoaa/895702 to your computer and use it in GitHub Desktop.
Save aanoaa/895702 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
my $str = "---------- ---- -- - - - -----------";
my %seen;
for my $i (1..9) {
my $j = 10 - $i;
while ($str =~ m/
(?=[ ]?[-]{$j})
(?<=-{$i})
/gx) {
$seen{pos($str)}++;
print "Matched: |$`<$&>$'|\n" if $seen{pos($str)} == 1;
}
}
__DATA__
Matched: |-<>--------- ---- -- - - - -----------|
Matched: |---------- ---- -- - - -<> -----------|
Matched: |---------- ---- -- - - - -<>----------|
Matched: |---------- ---- -- - - - --<>---------|
Matched: |--<>-------- ---- -- - - - -----------|
Matched: |---------- ---- -- - - - ---<>--------|
Matched: |---<>------- ---- -- - - - -----------|
Matched: |---------- ---- -- - - - ----<>-------|
Matched: |----<>------ ---- -- - - - -----------|
Matched: |---------- ---- -- - - - -----<>------|
Matched: |-----<>----- ---- -- - - - -----------|
Matched: |---------- ---- -- - - - ------<>-----|
Matched: |------<>---- ---- -- - - - -----------|
Matched: |----------<> ---- -- - - - -----------|
Matched: |---------- ---- -- - - - -------<>----|
Matched: |-------<>--- ---- -- - - - -----------|
Matched: |---------- ---- -- - - - --------<>---|
Matched: |--------<>-- ---- -- - - - -----------|
Matched: |---------- ---- -- - - - ---------<>--|
Matched: |---------<>- ---- -- - - - -----------|
Matched: |---------- ---- -- - - - ----------<>-|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
my $str = "---------- ---- -- - - - -----------";
while ($str =~ m/(-+) ?(-+)/g) {
print "Matched: |$`<$&>$'|\n";
print length $1, "\n";
print length $2, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment