Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple regex ...

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
Know it's simple,but got stuck ...

my Array holds a line that looks like:
Prinergy Update 3.1.0.2 c installed on Tue Jul 11 15:42:33 2006 Id: {3.1.0.2}

Need to get the last numbers between the {} .

the following regex does not work for me ....
for (@INFO) {
chomp;
if (/Prinergy Update/) {
s/{(.*)}/$1/ ;
$PRINVER=$_;
}
}

It prints :
Prinergy Update 3.1.0.2 c installed on Tue Jul 11 15:42:33 2006 Id: 3.1.0.2

Appreciate any help.



Long live king Moshiach !
 
Code:
 for (@INFO) {
        chomp;
        if (/Prinergy Update/) { # if the line contains "Prinergy Update"
            s/{(.*)}/$1/ ; # substitute the grouped bit minus the brackets
            $PRINVER=$_;
        }
    }
What you want is this;
Code:
$line="Prinergy Update 3.1.0.2 c installed on Tue Jul 11 15:42:33 2006 Id: {3.1.0.2}";
if ($line =~ /{(.*)}$/) {
  print $1;
}

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
This will build a hash of the Prinergy Updates - and they will store the dates they were installed

Code:
[b]#!/usr/bin/perl[/b]

s/([A-Z]{1}[a-z]{2} [A-Z]{1}[a-z]{2} \d+ \d+:\d+:\d+ \d{4}).*{(.*)}/$PRINVER{$2} = $1/e while <DATA>;

while (($key, $value) = each %PRINVER) {
  print "$key => $value\n";
}

[blue]__DATA__
blah
Prinergy Update 3.1.0.2 c installed on Tue Jul 11 15:42:33 2006 Id: {3.1.0.2}
blah blah
Prinergy Update 4.1.3.2 c installed on Tue Jul 11 16:32:44 2006 Id: {4.1.3.2}
blah blah blah
Prinergy Update 5.1.9.12 c installed on Tue Jul 11 15:34:55 2006 Id: {5.1.9.12}
blah blah
Prinergy Update 33.178.10.21 c installed on Tue Jul 11 10:23:11 2006 Id: {33.178.10.21}
blah[/blue]

Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top