Thanks to everyone's help so far, I think I am getting better with Regular expressions...
Don't know if they have been mentioned, if not:
perldoc perlretut perldoc perlre
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)
Note: there is not (.) after 198... is your data sane?
.233
I think I went to Crappy School, good parties... ;-)
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?
There are lots of possiblities. Naturally the \d\d?\d? works, which is just a digit followed by 2 optional digits, \d+ will get any number of digits in a row but won't be limited to 3. There are also combinations with braces, such as, \d{1,3} which is match at least once but not more than 3 times (see perlre above).
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?
A word character which includes your digits would be \w, you can also use character classes such as [A-Za-z]. You might want to consider using a word boundary \b. As above there are lots of ways to do it. Note that one of the names of the schools has a space so this will not be sufficient. One possible way:
if ($string =~ /^\d{1,3}\.\s([\w\s]+)\s\(\d+-\d+\)/) { print "Matched: $1\n"; }
Can't stress enough how important reading the docs is.....
HTH,
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>