RE: Regex Help
- From: tjohnson@xxxxxxxxxxxx (Timothy Johnson)
- Date: Tue, 18 Apr 2006 18:15:49 -0700
You need to anchor your regex. Your regex is matching '!!' because it
is matching an exclamation point followed by zero or more non
exclamation-point characters anywhere in the string.
Thus the first '!' is matching the regex, and the second '!' is outside
of your match.
Try this:
##################
use strict;
use warnings;
my $str = '!!';
print "$str\n" if $str =~ /^\![^!]*$/;
#################
The ^ in the match denotes the start of the string, while the $ denotes
the end (with an optional \n character).
-----Original Message-----
From: Jim [mailto:jkipp5@xxxxxxxxxxx]
Sent: Tuesday, April 18, 2006 5:52 PM
To: beginners@xxxxxxxx
Subject: Regex Help
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
.
- Follow-Ups:
- RE: Regex Help
- From: Jim
- RE: Regex Help
- Prev by Date: Re: Regex Help
- Next by Date: RE: Regex Help
- Previous by thread: RE: Regex help
- Next by thread: RE: Regex Help
- Index(es):
Relevant Pages
|