Operating System - HP-UX
1752584 Members
4138 Online
108788 Solutions
New Discussion

strange requirement & my regX is unable to match it

 
Mahesh S
Advisor

strange requirement & my regX is unable to match it

Hi,

I have a very strange below requirement and my regX is unable to match it.

Below is my script:
++++++++++++++++++++++++++++++++++
$_ = "Probable Cause :
Probable Cause 1, ProbablCause 2, Probable Cause 3
Probable Cause 1, Probable Cause 2, Probable Cause 3

Recommended Action :
Not Available

Replaceable :
Part Manufacturer : Not Available
Spare Part No. : Not Available
Additional Info : Not Applicable
";

my $match = "Probable Cause";


if (/$match\s+:([a-zA-Z0-9,\s]*):/m) {
print ("[$match] found\n");
print "[$1]\n";
} else {
print ("$match not found!\n");
}
+++++++++++++++++++++++++++++++++++++++++++

my requirement is to fetch values of certain attributes (e.g Spare Part No, Probable Cause etc) catch is
1. values can be in multiple lines having all kinds of chars except ":" some times not having anything also (including junk chars - bÿ5)
2. I will not know next attribute of my search (e.g if I am searching for Spare Part No I will not know Additional Info.)

All I know is I have multiple attributes each attributes ends with "\s:\s"

this above regX will not work for all conditions - can some one help me please please
- Thanks and Regards,
Mahesh S Rao
Little progress everyday... ...Adds upto big results
1 REPLY 1
Mahesh S
Advisor

Re: strange requirement & my regX is unable to match it

I managed to get with below regX thanks.

if (/$match\s+:([^:]*)/m) {
my $data;
print ("[$match] found\n");
$data = trim ($1);
print "[$data]\n";
} else {
print ("$match not found!\n");
}

trim function removes spaces, '\n' and last line if scalar ($1) is greater than 1 :)
I got what I was looking for it.
Little progress everyday... ...Adds upto big results