Link to home
Start Free TrialLog in
Avatar of crogg01
crogg01

asked on

Pattern Matching in Perl, regular expression

Hey,

I have a list of information for security indices that looks like this:

...
^MERV MerVal Argentina 1,417.890 12:02PM ET  11.480 (0.80%) Components, Chart, More
^FTSE FTSE 100 United Kingdom 4,910.30 11:29AM ET  8.60 (0.17%) Chart, More
...

I am looking to retrieve just the ticker and the description in a new file, i.e.:
^MERV, MerVal Argentina
^FTSE, FTSE 100 United Kingdom

The number in the description (e.g. FTSE) is distinguishable from the other numbers because of the "," or the "."
so I have used multiple patterns:
...
      if($testLine =~ m/(^\S+)(.*)(\d+)(,|.)(.*)/)
      {
            $testLine = "$1, $2\n";
            print TICKERSONLY $testLine;
      };      
...

but all seem to catch a value for $2 that is too greedy:
e.g.  MerVal Argentina 1,417.890 12:02PM ET

all I need is "Merval Argentina". What is wrong in my setup here ? Thanks for the help.



ASKER CERTIFIED SOLUTION
Avatar of jmcg
jmcg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of crogg01
crogg01

ASKER

That did it! Thanks
You may find you have an extra space or tab at the end of your string.