develooper Front page | perl.beginners | Postings from October 2011

How to put an AND in a regex?

Thread Next
From:
Hamann, T.D.
Date:
October 13, 2011 03:33
Subject:
How to put an AND in a regex?
Message ID:
2AE6512DA75354478DD9408686ABA09A03F72F4D@VSTPST01.nhncml.org

Hi,

I am trying to write a regex that should only match when certain patterns are not present, e.g. when a line does not start with either a digit or ALL-CAPS text. I figured I could use negative look-aheads for this.

I can write it as:

if (/^(?![[:upper:]][[:upper:]])/) {
    if (/^(?!\d)/) {
    s/^/<test>/;
    }
    else {
    }
}
else {
}

However, I was wondering whether there was a way of writing this as a single if loop, because there are much more than two situations that should not be matched.

I tried to write it as:

if (/^(?![[:upper:]][[:upper:]])|^(?!\d)/) {
s/^/<test>/;
}
else {
}

but this means if one option is not matched the other one is matched, which is not what I want. So I need something that does the equivalent of "Don't match this AND don't match this". Is this possible in a if loop, or should I use something else?

Thanks,

Regards,
Thomas Hamann

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About