Matching text not enclosed by parenthesis
问题 I am still learning Perl, so apologies if this is an obvious question. Is there a way to match text that is NOT enclosed by parenthesis? For example, searching for foo would match the second line only. (bar foo bar) bar foo ( bar foo (bar) (foo) ) 回答1: This is very far from "obvious"; on the contrary. There is no direct way to say "don't match" for a complex pattern (there is good support at a character level, with [^a] , \S etc). Regex is firstly about matching things, not about not-matching