On Tue, Apr 18, 2006 at 08:52:04PM -0400, Jim wrote:
> i am trying to match a '!' followed by any char but a '!' or no chars
> (string is only a '!')
> 
> this is what I have and it is not working:
> 
> $str = "!!";
> # this is not working.  it is matching "!!"
> print "$str\n" if $str =~ /\![^!]*/;
> 
> Thanks for any help

more effective:

    print "$str\n" if $str =~ /![^!]+/;

You didn't say anything about whether that bang should be the first
character in the string, and you weren't clear about whether more than
one non-bang character following that first bang is acceptable.  This
will match anywhere in the string, one or more non-bang characters
following a bang.  If you allow more characters and others beyond the
first following the initial bang can also be bangs, you might try this:

    print "$str\n" if $str =~ /![^!]/;

If only two characters are allowed on the line for a match, this would
work:

    print "$str\n" if $str =~ /^![^!]$/;

As someone else noted, this does smell a little like homework, but I'm
willing to give the benefit of the doubt this time.  You should really
have a look at the perldoc for regular expressions:

$ perldoc perlre

. . . assuming unixy command prompt syntax.

-- 
Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]
"There comes a time in the history of any project when it becomes necessary
to shoot the engineers and begin production." - MacUser, November 1990

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to