Regular expression behavior

Discussion in 'Perl' started by Adam Briska, Mar 1, 2004.

  1. Adam Briska

    Adam Briska Guest

    Given the script:

    --------
    use strict;
    use warnings;

    my $text = 'blob:blob';

    doit($text);
    doit($text);
    doit($text);

    sub doit
    {
    my ($aa) = @_;

    if( $aa =~ m?[^:]+:.*? ) {
    print "Good!\n";
    }
    else {
    print "Bad! \n";
    }
    }

    ----

    This produces the output:

    Good!
    Bad!
    Bad!

    -----

    I think that I may have a mistake on the regular expression syntax,
    but why does this show one behavior once and another behavior for all
    subsequent calls?

    If I change the regex to m/[^:]+:.*/ it works fine.

    I was under the impression that I could use any delimiter around my
    regex, but I seem to be mistaken.

    -Adam
     
    Adam Briska, Mar 1, 2004
    #1
    1. Advertising

  2. Adam Briska wrote:
    > Given the script:
    >
    > --------
    > use strict;
    > use warnings;
    >
    > my $text = 'blob:blob';
    >
    > doit($text);
    > doit($text);
    > doit($text);
    >
    > sub doit
    > {
    > my ($aa) = @_;
    >
    > if( $aa =~ m?[^:]+:.*? ) {
    > print "Good!\n";
    > }
    > else {
    > print "Bad! \n";
    > }
    > }
    >
    > ----
    >
    > This produces the output:
    >
    > Good!
    > Bad!
    > Bad!
    >
    > -----
    >
    > I think that I may have a mistake on the regular expression syntax,
    > but why does this show one behavior once and another behavior for all
    > subsequent calls?
    >
    > If I change the regex to m/[^:]+:.*/ it works fine.
    >
    > I was under the impression that I could use any delimiter around my
    > regex, but I seem to be mistaken.


    So it seems.

    Why didn't you check the docs for the m// operator before asking here?

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 1, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,332
  2. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    860
    Alan Moore
    Dec 2, 2005
  3. GIMME
    Replies:
    3
    Views:
    11,997
    vforvikash
    Dec 29, 2008
  4. Mantorok Redgormor
    Replies:
    70
    Views:
    1,796
    Dan Pop
    Feb 17, 2004
  5. Neroku
    Replies:
    12
    Views:
    549
    Flash Gordon
    Feb 12, 2007
Loading...

Share This Page