[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] Yet another regex question

On Sat, 2005-08-13 at 02:48 -0400, Jim Popovitch wrote:
> On Fri, 2005-08-12 at 21:29 -0400, Christopher Fowler wrote: 
> > I guess what I'm asking is if there is a way to catch 'XMI001' instead
> > of '%\sXMI001' without using the anchors
> How about using "[^ ]XMI001" where the brackets contain a (set of) valid
> character(s) to match against, but in this case a leading carrot '^' in
> the brackets indicates that we do NOT want to match against the set of
> characters.
> So, a regmatch of "[^ ]XMI001" would match "XMI001" and "zXMI001" but
> not " XMI001" since the brackets contain a negated space (i.e. no space
> before XMI001) 

I think the problem with that is that it requires something to be before
the X.  Something has to be there but no space.  I'm using perl to test
the ideas.

[cfowler at shuttle ~]$ ./regex.pl '[^ ]XMI001' 'XMI001'

[cfowler at shuttle ~]$ cat regex.pl 
die "regex.pl <regex> <test string>\n" unless $ARGV[0] and $ARGV[1];
my $regex = $ARGV[0];
if($ARGV[1] =~ m/$regex/) {
        print "Yes\n";
} else {
        print "No\n";