Help for this page

Select Code to Download


  1. or download this
       is($actual, $expected, $descriptionOfWhatYouTried);
    
    ...
    
       # to check what got captured by a regular expression
       is(eval { 'abcdef' =~ /^(\w+)/; $1 }, 'ab', q{tried /^\w+/});
    
  2. or download this
    not ok 1 - tried /^\w+/
    #   Failed test 'tried /^\w+/'
    ...
    #     expected: 'ab'
    1..1
    # Looks like you failed 1 test of 1.
    
  3. or download this
       #changed is to isnt
       #This doesn't work. Captures 'abcdef' instead of just 'ab'
    
       isnt(eval { 'abcdef' =~ /^(\w+)/; $1 }, 'ab', q{tried /^\w+/});
    
  4. or download this
    #using perl MyExperiments.pl
    
    ...
    MyExperiments.pl....ok
    All tests successful.
    Files=1, Tests=10,  0 wallclock secs ( 0.05 cusr +  0.04 csys =  0.09 
    +CPU)
    
  5. or download this
    use strict;
    use warnings;
    ...
    
    #BINGO! this worked
    is(eval {'abcdeee' =~ /(.)(\1+)/;"$1$2"}, 'eee', q{using /(.)(\1+)/;"$
    +1$2"});
    
  6. or download this
    use strict;
    use warnings;
    ...
    
    regexRepeat('abcdeeef', 'eee');   #only one to find
    regexRepeat('abbb;eeef', 'bbb');  #should find first