On Oct 13, 3:33 am, [email protected] ("Hamann, T.D. (Thomas)")
wrote:

>
> 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?

Yet another way:

unless (  /^  (?: [[:upper:]]{2} | \d ) /x  ) {
      ...
}

--
Charles DeRykus


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to