in reply to Using negative lookahead

The others have already given you some excellent answers. I just wanted to point out Regexp::Common::delimited as well as Text::Balanced, which contain functions that implement something like what you are doing. Also, this task sounds like something that one encounters when parsing formats for which parsers might already exist, a common one being Text::CSV. Also, personally I find it easier to write my regex tests as I showed in Re: How to ask better questions using Test::More and sample data.

Replies are listed 'Best First'.
Re^2: Using negative lookahead
by ibm1620 (Hermit) on Oct 19, 2017 at 23:13 UTC
    Thank you for the pointer to Test::More. It's very timely since just today there's been a discussion at work of formalizing QA test cases.

    I have used Regexp::Common::delimited and Text::CSV. But in addition to simply wanting to understand negative lookahead, the problem I'm working on involves making a best-effort attempt to tokenize strings that don't conform to any single set of rules. (The strings are metadata declarations of the parameter lists that 100 or so different programs read and parse with their own idiosyncratic logic.) I'll be making guesses (programatically) about what I'm encountering, and hoping to break the strings into meaningful units, with no expectation of 100% correctness.

    Also, the machine this is to run on is pretty locked down and the sysadmins are reluctant to install CPAN modules. You pick your battles.... :-(