[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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.



0
crogg01
Asked:
crogg01
  • 2
1 Solution
 
jmcgOwnerCommented:
Try making the first instance of (.*) nongreedy by saying (.*?)
0
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now