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