Home: Perl Programming Help: Regular Expressions:
regular expression

New User

Sep 24, 2014, 12:35 PM

Views: 38916
regular expression

how do i create a regular expression for a nfl players that threw for 3000 or more yards and more than 30 touchdowns.


Name ,team,position,350,541,64.7,33.8,"4434",8.2,277.1,"30",7,197,36.4,83T,55,17,50,103.2

from above i am interested in only 4434 and 30 (one in double "").


Sep 24, 2014, 9:18 PM

Views: 38909
Re: [moneysab] regular expression

I doubt that you can. Even if you can, it would be a bad solution to your problem because it is far beyond what regular expressions are intended to do. A range of numeric values is not a 'pattern'.

You have a .csv file. You first have to parse it into columns. Based on your single sample, you could split the line on commas. A better solution is to use a module such as Text::CSV.
Good Luck,

Veteran / Moderator

Sep 24, 2014, 11:22 PM

Views: 38907
Re: [moneysab] regular expression

You probably can do it with a regex, but it would be a very very bad idea.
Use a module such as Text::CSV or use split:

my ($distance, $touchdowns) = (split /,/, $string) [7, 10];