473,811 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extracting data using regular expression

51 New Member
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
Aug 16 '08 #1
9 2295
sasimca007
129 New Member
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.
Aug 16 '08 #2
pavanponnapalli
51 New Member
$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.
Aug 16 '08 #3
sasimca007
129 New Member
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
Aug 16 '08 #4
pavanponnapalli
51 New Member
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,sympho ny,apps,HTTP in an array

pavan
Aug 16 '08 #5
sasimca007
129 New Member
that means, u want
May,symfony,HTT P are between //. U want After GET and in between the //.
In the before example 1.1 is after / u doesn't want it?
Aug 16 '08 #6
pavanponnapalli
51 New Member
that means, u want
May,symfony,HTT P 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
Aug 16 '08 #7
sasimca007
129 New Member
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
Aug 16 '08 #8
pavanponnapalli
51 New Member
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.
Aug 16 '08 #9
eWish
971 Recognized Expert Contributor
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
Aug 16 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1619
by: Richard L Rosenheim | last post by:
I have some text where I need to extract some pieces from. The text will be in a format like this: a string description color="red" type="unknown" In the above example, I would be looking to extract the word "red". There's couple of ways I could approach the problem. I could use IndexOf to search for the string 'color=' and then extract the value using the Substr method. Or, I could use a regular expression like:
5
2960
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past, I have used individual entry fields for each variable. I would now like to use text area boxes to simplify the data entry (this way, data can be produced by another program--FORTRAN, "C", etc.--but analyzed online, so long as it is first...
1
2808
by: Cognizance | last post by:
Hi gang, I'm an ASP developer by trade, but I've had to create client side scripts with JavaScript many times in the past. Simple things, like validating form elements and such. Now I've been assigned the task of extracting content from a given HTML page. If anyone's familiar with the Yahoo! Store order confirmation screen, I need to be able to grab the total amount from the table to the right-hand side. (Sample File:
0
1490
by: system7designs | last post by:
I am trying to set up a form where users upload zips, the zip is extracted into their specific user directory and then the zip file is deleted (These photos are then displayed on their userpage) The problem occurs when someone zips a folder and/or uses mac osx to create the zip. The resource forks (files that begin with ._) get treated as regular images, macosx also creates a folder in the zip called __MACOSX and I can't figure out...
4
3996
by: Tony Clarke | last post by:
Hi All, I have been trying to extract data from a text file using the fscanf() functions and sscanf() functions. The file is of various characters and integers separated by semicolons, the problem I'm having is that each line is of varying length and the fields separated by semicolons are of varying length also. Is there a way that I could check the first field and depending on this extract data from certain fields contained in this...
0
1639
by: Mico | last post by:
I would be very grateful for any help with the following: I currently have the code below. This opens a MS Word document, and uses C#'s internal regular expressions library to find if there is a match within this document. When I run the code I get a parser error - I think there is an escape character in the Word doc format, or perhaps trying to do a match with the entire document is not a good idea. public DataRow getMatches()
16
10980
by: Preben Randhol | last post by:
Hi A short newbie question. I would like to extract some values from a given text file directly into python variables. Can this be done simply by either standard library or other libraries? Some pointers where to get started would be much appreciated. An example text file: ----------- Some text that can span some lines.
7
3083
by: Tempo | last post by:
Hello. I am having a little trouble extracting text from a string. The string that I am dealing with is pasted below, and I want to extract the prices that are contained in the string below. Thanks in advanced for any and all help. Thank you. <span class="sale"> $14.99 </span>, <span class="sale">
3
16924
by: Johny | last post by:
Does anyone know about a good regular expression for URL extracting? J.
3
2812
by: MCH | last post by:
hi there, I am working with a HTML-like text with boost:regex. For example, the following pattern might occur in my text <abc efg> <p>EFG</p 12<3> In this case, I would like to extract everything between and replace with <pre>, with </pre>. Meanwhile, everything outside should be unchaged except that < is
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.