Solved

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

Posted on 2000-05-10
8
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

628 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