Solved

Regular Expressions

Posted on 2003-11-27
3
294 Views
Last Modified: 2012-05-04
Well I'm new to regular expressions so I need some help:
I need some regexps that parse the followin lines:

>>> Map: goldrush
Overall stats for: Snyke (1 Round)
Luger    :  20.5    9/44       1      0         0
Damage Given: 4980    Team Damage: 897
Damage Recvd: 4129
Rank: Hauptmann (519 XP)
Heavy Weapons  0 (15/20)          0
Axis   Hyp3r10n         65  20   1 11  76  14 12305  4276 2221   1523
Stats recorded: 00:25:10 (27 Nov 2003)

They are just sample log files from Wolfenstein Enemy Territory If you need it I will post an entire log.
Notice that I need as much information from the above as possible...
0
Comment
Question by:Snyke
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
pjdietz earned 125 total points
ID: 9832379
Can you be more specific? I don't understand what you want to do with the lines.

If you just want to pull out the numeric data, you could use a regEx along the lines of:

[^0-9]*([0-9]*)


Here's what it means:

* [] designates a set. It will match any characters you list in the set, and you can specify ranges of characters (e.g., 0-9 fo all digits, a-z for all letters)

* ^ A set with a ^ character at the beginning designates a set that while match any character that is NOT inside the brackets (e.g., [^0-9] will match anything that is not a numeric characeter.

* () are used to store a group for future reference. You can store a number of groups in a regular expression, and then refere to them with \1, \2, \3, etc. Here's an example.

$stringToParse = "Damage Given: 4980    Team Damage: 897"
$regEx =  "[^0-9]*([0-9]*)[^0-9]*([0-9]*)"

When you use php's ereg function, you can get an array containing all of the values it found in the stored groups.

if ereg($stringToParse, $regEx, $resultsArray) { // do stuff if it found a match }

$resultsArray is passed by reference into the ereg function, so it isn't a variable you need to do anything with before calling ereg. After you call ereg, you'll get the following results.

$resultsArray = Array(
[0] => "Damage Given: 4980    Team Damage: 897" // the entire string matched
[1] => "4980" // The first stored group
[2] => "897" // The second stored group

Hope this helps!




0
 
LVL 1

Author Comment

by:Snyke
ID: 9860454
Yep that helps, thank you very much.
I was able to do my regular expressions easily for myself.
0
 
LVL 1

Expert Comment

by:pjdietz
ID: 9860781
Glad to help!
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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 24
only allow numbers with preg match 4 25
WordPress TK Title 8 24
using php variable inside javascript 5 13
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

23 Experts available now in Live!

Get 1:1 Help Now