aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/e-choroba/perl/ch-2.pl
blob: 3ebdf460d3b40fc34c84286c0077fd96c1933f26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/perl
use warnings;
use strict;
use experimental qw( signatures );

sub b_after_a($str) {
    $str =~ /^           # Start of the string.
             [^b]*       # Anything up to the first b.
             b           # The first b.
             (?!         # Not folllowed by...
                 .*      # ... anything...
                 a       # ... and a.
             )
            /x
}

use Test::More tests => 4;

ok b_after_a('aabb'), 'Example 1';
ok ! b_after_a('abab'), 'Example 2';
ok ! b_after_a('aaa'), 'Example 3';
ok b_after_a('bbb'), 'Example 4';