Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 16th, 2008, 08:36 AM
Member
 
Join Date: May 2008
Posts: 50
Default Extracting data using regular expression

hi,
i have data as under.
Expand|Select|Wrap|Line Numbers
  1.  127.0.0.1 - - [05/May/2008:14:28:56 +0530] "GET /favicon.ico HTTP/1.1" 404 292
  2. 127.0.0.1 - - [05/May/2008:14:28:56 +0530] "GET /favicon.ico HTTP/1.1" 404 292
  3. 127.0.0.1 - - [05/May/2008:14:30:33 +0530] "GET /pear/symfony/ HTTP/1.1" 404 294
  4. 127.0.0.1 - - [05/May/2008:14:30:39 +0530] "GET /symfony/ HTTP/1.1" 404 289
  5. 127.0.0.1 - - [05/May/2008:14:32:35 +0530] "GET /symfony/sf_sandbox HTTP/1.1" 404 299
  6. 127.0.0.1 - - [05/May/2008:14:32:49 +0530] "GET / HTTP/1.1" 200 3466
  7. 127.0.0.1 - - [05/May/2008:14:32:49 +0530] "GET /appserv/members.gif HTTP/1.1" 200 755
  8. 127.0.0.1 - - [05/May/2008:14:32:49 +0530] "GET /appserv/flag-thai.png HTTP/1.1" 200 545
  9. 127.0.0.1 - - [05/May/2008:14:32:49 +0530] "GET /appserv/annoicon.gif HTTP/1.1" 200 1182
  10. 127.0.0.1 - - [05/May/2008:14:32:49 +0530] "GET /appserv/flag-english.png HTTP/1.1" 200 576
  11. 127.0.0.1 - - [05/May/2008:14:32:49 +0530] "GET /appserv/softicon.gif HTTP/1.1" 200 474
  12. 127.0.0.1 - - [05/May/2008:14:32:58 +0530] "GET /pear/ HTTP/1.1" 404 286
  13. 127.0.0.1 - - [05/May/2008:14:33:07 +0530] "GET /PEAR HTTP/1.1" 404 285
  14. 127.0.0.1 - - [05/May/2008:14:35:14 +0530] "GET /PEAR HTTP/1.1" 301 313
  15. 127.0.0.1 - - [05/May/2008:14:35:14 +0530] "GET /PEAR/ HTTP/1.1" 200 3264
  16. 127.0.0.1 - - [05/May/2008:14:35:15 +0530] "GET /icons/back.gif HTTP/1.1" 200 216
  17. 127.0.0.1 - - [05/May/2008:14:35:14 +0530] "GET /icons/blank.gif HTTP/1.1" 200 148
  18. 127.0.0.1 - - [05/May/2008:14:35:15 +0530] "GET /icons/folder.gif HTTP/1.1" 200 225
  19. 127.0.0.1 - - [05/May/2008:14:35:15 +0530] "GET /icons/unknown.gif HTTP/1.1" 200 245
  20. 127.0.0.1 - - [05/May/2008:14:35:19 +0530] "GET /PEAR/symfony/ HTTP/1.1" 200 7196
  21. 127.0.0.1 - - [05/May/2008:14:35:29 +0530] "GET /PEAR/symfony/sf_sandbox/ HTTP/1.1" 200 3680
  22. 127.0.0.1 - - [05/May/2008:14:35:29 +0530] "GET /icons/script.gif HTTP/1.1" 200 242
  23. 127.0.0.1 - - [05/May/2008:14:35:34 +0530] "GET /PEAR/symfony/sf_sandbox/apps/ HTTP/1.1" 200 1169
  24. 127.0.0.1 - - [05/May/2008:14:35:35 +0530] "GET /PEAR/symfony/sf_sandbox/apps/backend/ HTTP/1.1" 200 1580
  25. 127.0.0.1 - - [05/May/2008:14:35:37 +0530] "GET /PEAR/symfony/sf_sandbox/apps/backend/config/ HTTP/1.1" 200 3217
  26. 127.0.0.1 - - [05/May/2008:14:35:39 +0530] "GET /PEAR/symfony/sf_sandbox/apps/backend/config/app.yml HTTP/1.1" 200 22
  27. 127.0.0.1 - - [05/May/2008:14:35:44 +0530] "GET /PEAR/symfony/sf_sandbox/apps/backend/config/security.yml HTTP/1.1" 200 26
  28. 127.0.0.1 - - [05/May/2008:14:35:49 +0530] "GET /PEAR/symfony/sf_sandbox/apps/backend/config/config.php HTTP/1.1" 200 851
  29. 127.0.0.1 - - [05/May/2008:14:37:56 +0530] "GET /PEAR/symfony/sf_sandbox/apps/backend/config/view.yml HTTP/1.1" 200 375
  30.  
what i need is i want values between two //, that too after GET. if the values between // have spaces, those values should not be retrieved.

Thanks,
pavan

Last edited by eWish; August 16th, 2008 at 04:46 PM. Reason: Please use the[code][/code] tags for data as well
Reply
  #2  
Old August 16th, 2008, 08:48 AM
Member
 
Join Date: Sep 2007
Posts: 94
Default

Expand|Select|Wrap|Line Numbers
  1. $s = '127.0.0.1 - - [05/May/2008:14:30:33 +0530] GET /pear/symfony/ HTTP/1.1';
  2. if($s !~ /GET(\s*)\/(\w*)\s(\w*)\//)
  3. {
  4.     if($s =~ /GET(\s*)\/(\w*)\//)
  5.     {    print "Success $2\n";    }
  6. }
In regular expression i typed \/ this is not V this is combination of \ and / ok. Try with this almost it comes if u have any doubt give reply.

Last edited by eWish; August 16th, 2008 at 04:47 PM. Reason: Please use the[code][/code] tags
Reply
  #3  
Old August 16th, 2008, 09:32 AM
Member
 
Join Date: May 2008
Posts: 50
Default

Quote:
Originally Posted by sasimca007
$s = '127.0.0.1 - - [05/May/2008:14:30:33 +0530] GET /pear/symfony/ HTTP/1.1';
if($s !~ /GET(\s*)\/(\w*)\s(\w*)\//)
{
if($s =~ /GET(\s*)\/(\w*)\//)
{ print "Success $2\n"; }
}

In regular expression i typed \/ this is not V this is combination of \ and / ok. Try with this almost it comes if u have any doubt give reply.
hi,
Actually how to get values between / and / without using GET ? I need to get all the values in an array .

Regards,
pavan.
Reply
  #4  
Old August 16th, 2008, 10:07 AM
Member
 
Join Date: Sep 2007
Posts: 94
Default

127.0.0.1 - - [05/May/2008:14:30:39 +0530] "GET /symfony/ HTTP/1.1" 404
289

In tha above example what text u want exactly i.e)
symfony
(0r)
sympony,HTTP
Reply
  #5  
Old August 16th, 2008, 10:10 AM
Member
 
Join Date: May 2008
Posts: 50
Default

Quote:
Originally Posted by sasimca007
127.0.0.1 - - [05/May/2008:14:30:39 +0530] "GET /symfony/ HTTP/1.1" 404
289

In tha above example what text u want exactly i.e)
symfony
(0r)
sympony,HTTP
hi,
i want everything between // in an array in that line. there may be one // or multiple // like 127.0.0.1 - - [05/May/2008:14:35:34 +0530] "GET /PEAR/symfony/sf_sandbox/apps/ HTTP/1.1" 200 1169
here i want May,PEAR,symphony,apps,HTTP in an array

pavan

Last edited by pavanponnapalli; August 16th, 2008 at 10:14 AM. Reason: doubt
Reply
  #6  
Old August 16th, 2008, 10:15 AM
Member
 
Join Date: Sep 2007
Posts: 94
Default

that means, u want
May,symfony,HTTP are between //. U want After GET and in between the //.
In the before example 1.1 is after / u doesn't want it?
Reply
  #7  
Old August 16th, 2008, 10:50 AM
Member
 
Join Date: May 2008
Posts: 50
Default

Quote:
Originally Posted by sasimca007
that means, u want
May,symfony,HTTP are between //. U want After GET and in between the //.
In the before example 1.1 is after / u doesn't want it?
hi,
no Get is not compulsary in all files. There may be get or there may not be.

Regards,
pavan
Reply
  #8  
Old August 16th, 2008, 11:21 AM
Member
 
Join Date: Sep 2007
Posts: 94
Default

Expand|Select|Wrap|Line Numbers
  1. if($s =~ /\"(\w*)(\s*)\//g)
  2. {    print "$'\n";$s = $';    }
  3. while($s =~ /(\w*)\//g)
  4. {    $s = $';print "$1\n";push @arr,$1;    }
  5. print "@arr\n";
try this code man

Last edited by eWish; August 16th, 2008 at 04:48 PM. Reason: Please use the[code][/code] tags
Reply
  #9  
Old August 16th, 2008, 11:59 AM
Member
 
Join Date: May 2008
Posts: 50
Default

Quote:
Originally Posted by sasimca007
if($s =~ /\"(\w*)(\s*)\//g)
{ print "$'\n";$s = $'; }
while($s =~ /(\w*)\//g)
{ $s = $';print "$1\n";push @arr,$1; }
print "@arr\n";

try this code man
hey,
thank u very much.
Reply
  #10  
Old August 16th, 2008, 10:19 PM
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 833
Default

pavanponnapalli and sasimca007,

When posting code samples here at Bytes.com it is expected of everyone to use the [code][/code] tags. It will preserve the format and is much more readable. Also, please use the code tags when posting sample data as well.

--Kevin
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles