Re: regexp pattern matching
- From: shawnhcorey@xxxxxxxx (Mr. Shawn H. Corey)
- Date: Thu, 29 Jun 2006 14:31:08 -0400
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/
.
- Follow-Ups:
- Re: regexp pattern matching
- From: Mr. Shawn H. Corey
- Re: regexp pattern matching
- References:
- regexp pattern matching
- From: Hair
- regexp pattern matching
- Prev by Date: Re: regexp pattern matching
- Next by Date: Re: regexp pattern matching
- Previous by thread: Re: regexp pattern matching
- Next by thread: Re: regexp pattern matching
- Index(es):
Relevant Pages
|