Solved

Parsing to get a part of a string from a string!

Posted on 2000-05-10
8
226 Views
Last Modified: 2010-03-05
for example assuming the result this line of code
$label_and_OID = `idlcall $NROID get_all '"RemoteControl" $SIZE'`;
is:
=====================================================
{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}OBJECT_NIL
=====================================================

Now I need to parse the result of the IDLCALL inoreder to
get the below info stored into the respective variables

$HUB_REGION_NUMBER=1234567889
$RC_OBJECT_ID=1234567889.1.1028

Thanks.  I need this Regular Expression/pattern matching like ASAP.
I would appreciate your HELP!!

CODER.
0
Comment
Question by:CODER
  • 5
  • 2
8 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2797577
here is the solution using reg exps...

#!/usr/local/bin/perl

$label_and_OID='{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}
OBJECT_NIL ';

$label_and_OID=~ /{\d+\s+{\s+((\d+)\.\d+\.\d+)[A-Za-z]+/;

$HUB_REGION_NUMBER=$2;
$RC_OBJECT_ID=$1;

print $HUB_REGION_NUMBER,"\n";
print $RC_OBJECT_ID,"\n";
0
 

Author Comment

by:CODER
ID: 2797597
{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}OBJECT_NIL

the string that says "test" will have an actual string that looks like so:

PPP code.servername.iga.app.bbrc-object

and I will want to also extract part of this string from the part that reads

 iga.app.bbrc-object

and store it in a variable called
$RC_LABEL

thanks....
0
 

Author Comment

by:CODER
ID: 2797624
for example assuming the result this line of code
$label_and_OID = `idlcall $NROID get_all '"RemoteControl" $SIZE'`;
is:
=====================================================
{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}OBJECT_NIL
=====================================================
the string that says "test" will have an actual string that looks like so:

PPP code.servername.iga.app.bbrc-object
and I will want to also extract part of this string from the part that reads

iga.app.bbrc-object
Now I need to parse the result of the IDLCALL inoreder to
get the below info stored into the respective variables

$HUB_REGION_NUMBER=1234567889
$RC_OBJECT_ID=1234567889.1.1028
$RC_LABEL = iga.app.bbrc-object

Thanks.  I need this Regular Expression/pattern matching like ASAP.
I would appreciate your HELP!!

                      CODER.
0
 
LVL 12

Accepted Solution

by:
geotiger earned 50 total points
ID: 2797803
Here is the code:


#!/usr/local/bin/perl

$test = "PPP code.servername.iga.app.bbrc-object";

$str = "{1 { 1234567889.1.1028PcRC::RemoteControl# $test { { null }}}}OBJECT_NIL";

# $HUB_REGION_NUMBER=1234567889
# $RC_OBJECT_ID=1234567889.1.1028
# $RC_LABEL = iga.app.bbrc-object

print "$str\n";
if ($str =~ /{1 {\s*(\d+)([\d.]+)\w*::\w*#\s*PPP\s*\w*\.\w*\.([\w.]+)/) {
    print "1: $1: $2 : $3\n";
    $HUB_REGION_NUMBER=$1;
    $RC_OBJECT_ID="$1$2";
    $RC_LABEL=$3;
}
print "\$HUB_REGION_NUMBER=$HUB_REGION_NUMBER\n";
print "\$RC_OBJECT_ID=$RC_OBJECT_ID\n";
print "\$RC_LABEL=$RC_LABEL\n";



The output is :

{1 { 1234567889.1.1028PcRC::RemoteControl# PPP code.servername.iga.app.bbrc-object { { null }}}}OBJECT_NIL
1: 1234567889: .1.1028 : iga.app.bbrc
$HUB_REGION_NUMBER=1234567889
$RC_OBJECT_ID=1234567889.1.1028
$RC_LABEL=iga.app.bbrc
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:maneshr
ID: 2797880
CODER,

you have to be clear about while describing the problem. nowhere in your original Q did you clarify about test being a variable.

now you have decided to change the Q. in such cases its very difficult to provide a properly working code/code snippet.
0
 

Author Comment

by:CODER
ID: 2798012
maneshr :I AM SORRY ABT THAT... I WILL NOT MAKE THAT ERROR AGAIN.  MY BADD!!!!!
0
 

Author Comment

by:CODER
ID: 2798026
HEY
I am curious as to how
if ($str =~ /{1 {\s*(\d+)([\d.]+)\w*::\w*#\s*PPP\s*\w*\.\w*\.([\w.]+)/)

gets the iga.app.bbrc  string that I want... what part of that regular expression does this?  I see where it strips the PPP away... where does it strip the
=============
code.servername.
=============
is it the \s*\w*\.\w*\.  ???

PPP code.servername.iga.app.bbrc-object"

thanks
0
 

Author Comment

by:CODER
ID: 2798077
geotiger's comment
====================================================
#!/usr/local/bin/perl

 $test = "PPP code.servername.iga.app.bbrc-object";

$str = "{1 { 1234567889.1.1028PcRC::RemoteControl# $test { { null }}}}OBJECT_NIL";

                      # $HUB_REGION_NUMBER=1234567889
                      # $RC_OBJECT_ID=1234567889.1.1028
                      # $RC_LABEL = iga.app.bbrc-object

 print "$str\n";
 if ($str =~ /{1 {\s*(\d+)([\d.]+)\w*::\w*#\s*PPP\s*\w*\.\w*\.([\w.]+)/) {
                          print "1: $1: $2 : $3\n";
                          $HUB_REGION_NUMBER=$1;
                          $RC_OBJECT_ID="$1$2";
                          $RC_LABEL=$3;
                      }
                      print "\$HUB_REGION_NUMBER=$HUB_REGION_NUMBER\n";
                      print "\$RC_OBJECT_ID=$RC_OBJECT_ID\n";
                      print "\$RC_LABEL=$RC_LABEL\n";



                      The output is :

                      {1 { 1234567889.1.1028PcRC::RemoteControl# PPP code.servername.iga.app.bbrc-object { { null }}}}OBJECT_NIL
                      1: 1234567889: .1.1028 : iga.app.bbrc
                      $HUB_REGION_NUMBER=1234567889
                      $RC_OBJECT_ID=1234567889.1.1028
                      $RC_LABEL=iga.app.bbrc
====================================================
NOW SUPPOSING for my $RC_LABEL variable, I want the
complete info which is:
PPP code.servername.iga.app.bbrc-object

how would I do this??????
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now