On Jan 20, 2004, at 4:28 PM, Lewick, Taylor wrote:

Thanks to everyone's help so far, I think I am getting better with
Regular expressions...



Need a little help on this one

This is sample data, not accurate..



1. St Joes (15-0)

.875

(2-0)

2. Kentucky (12-2)

.850

(1-0)

10. Kansas (12-2)

.778

(1-1)

198 Crappy School (2-9)

.233



and on and on..

I am trying to match only the schools name, and I have the following reg
ex




if (/^\d\.\s([A-Z]\D+)/)  (This says match starting at the beginning of
the line a digit followed by a period followed by a space followed by a
Capital letter followed by any amount of nondigit characters)



This matches the schools that are 1 through 9, but not 10-200.



What is the best way to say match 1, 2 or 3 numbers? With a plus after
the \d or do can I tell it to specifically match only 1 2 or 3 digits?

You could do either:


\d+ # one or more digits

\d{1,3} # one to three digits

I actually prefer the first. It's simpler, should work just fine with the period to keep us from grabbing too much, and is even more flexible since it can handle bigger numbers.

Also, this is returning the first parentheses mark "(".  How do I tell
it not to match that... I know I have to replace \D+ but what with?
What is the metacharacter if there is one to just match a letter?

m/
^\d+\.\s+ # a number, followed by a period and some whitespace
([A-Za-z ]+?) # the school name, one or more letters and spaces, capture
\s+\( # some whitespace and a paren
[^)]+ # one or more non-paren characters
\)\s*$ # final paren, optional whitespace, end of line
/x


If you need to capture other parts, just add parens. You really don't even need the last two lines of the expression, if you only want to capture the school name.

Good luck.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to