Perl regular expression question
December 21, 2005 2:04 PM Subscribe
Perl regular expression question inside. Trying to parse a list of items...
posted by pornucopia to Computers & Internet (8 answers total)
Ok, I have a file listing things formatted like this:
I'm trying to use a regular expression to determine whether a given item comes after foobar or after foobaz. I'm doing something like this:
$variable = "b3";
$text_of_file =~ /Items (\S+?):.*?$variable/;
I figured that adding a ? after the * to make it non-greedy would mean that it would print "foobaz", but unfortunately it's printing "foobar".
Can someone suggest a better way to do this? It occured to me that I could split the list up into sections using something like:
@sections = split(/foob\S\S/, $text_of_file)
but that seemed like a lame hack, and it seems like you should be able to easily do this using a regex.