Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2000-05-10
8
Medium Priority
?
251 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
Industry Leaders: 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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

704 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