On Thu, 2006-29-06 at 13:40 -0400, Hair wrote: > Hello, I have a pattern matching question, that I can't seem to find the > answer to either online or in books, so here is the pattern I am trying to > match, and hopefully some kind soul will give me pointers: > > > The satchel contains the following items (97): item1, item2, etc etc > > > I can match the first part, but I am trying to extract the item list. I > am having problems getting the pattern to match the (97) [note, that > number varies] and the : and just give me the items in the list. > > Yes, this is for a mud, but using perl regex in tinyfugue. I had help on > the tf list getting the majority of this working, but the (97): still gets > added to my list and I don't want it. TIA for any help. > > --Tommy Vielkanowitz > >
OK, here are some pointers: 1. Create a file with lines you want to match. Use copy & paste rather than generating them by hand; you'll avoid typing errors. Try to include as many just-barely-hits as you can, that is, those lines you want to match but are on the boundaries. The satchel contains the following item (1): item1 The satchel contains the following items (2): item1, item2 The satchel contains the following items (3): item1, item2, item3 2. Create a pattern that has all the common parts and replace the parts that vary with '.*' Be sure to escape any meta-characters. m/The satchel contains the following item.* \(.*\): .*/ 3. Add parentheses to capture parts. m/The satchel contains the following item.* \((.*)\): (.*)/ 4. Refine the match by replace the '.*' with more specific matches. m/The satchel contains the following items? \((\d+)\): (.*)/ 5. Be sure to record the parts immediately after the match. New matches will overwrite them. m/The satchel contains the following items? \((\d+)\): (.*)/ my $count_of_items = $1; my $item_list = $2; Hope this helps. -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>