Regular expression behavior

A

Adam Briska

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
 
G

Gunnar Hjalmarsson

Adam said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top