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.



crogg01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
jmcgOwnerCommented:
Try making the first instance of (.*) nongreedy by saying (.*?)
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
crogg01Author Commented:
That did it! Thanks
0
 
jmcgOwnerCommented:
You may find you have an extra space or tab at the end of your string.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.