Berkeley CSUA MOTD:Entry 27599
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2003/3/4-5 [Computer/SW/Languages/Perl] UID:27599 Activity:moderate
3/4     perl god, I want to match AAA but not AAAA, so I tried
        perl -ne 'print if /A{3}/'
        How come it still matches both AAA and AAAA?  - perl tyro
        \_ /(?<!A)A{3}(?!A)/
        \_ try /[^A]A{3}[^A]/ (edited)
           your syntax matches AAAA because AAA is within AAAA (ie, it could
           be AAA or AAAA or AAAAA or sdfAAAsdfa, and it'd match). This syntax
           says after the 3 A's, match any character that's NOT A.
           \_ you probably want something like
              /^(.*[^A])?A{3}([^A].*)?$/
              (otherwise you won't match "AAAfgdsfg" or "dsgffdsAAA") -alexf
              \_ This won't match multiple AAA's on the same line, will it?
                 (i'm still a grade schooler in regexp foo)
                 \_ Yes, it will match the first set, so that's still a match.
                    But it makes assumptions about lines and so forth.