http://www.perlmonks.org?node_id=37662

Mina has asked for the wisdom of the Perl Monks concerning the following question: (strings)

My record is something like this:

News, Product Information, Shopping information, Reference Materials (i.e. dictionaries), Research Materials (i.e. journals, databases), Educational, Hobby / Special Interest (i.e. genealogy, cooking), Financial Material

I'd like to split it by fields, but the commas in the parentheses are a problem.

My initial thought was to use split /,\ [A-Z]/; but would eat away the first letters of the fields.

Better ideas? (maybe the reg exp needs to be craftier, I don't know my brain has turned into jello).

~mina

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I split on ',' followed by a capital letter?
by japhy (Canon) on Oct 20, 2000 at 18:15 UTC
    You're on the right track. Use a positive look-ahead in your regex:
    @fields = split /, (?=[A-Z])/, $string;
Re: How do I split on ',' followed by a capital letter?
by kilinrax (Deacon) on Oct 20, 2000 at 18:16 UTC
    I'm pretty sure:
    my @array = split /,\s(?=[A-Z])/, $string;
    will work.

    Originally posted as a Categorized Answer.

Re: How do i split on
by Mina (Acolyte) on Oct 20, 2000 at 18:29 UTC
    Thanks guys. =)

    Originally posted as a Categorized Answer.