Solved

Regular Expressions

Posted on 2003-11-27
3
295 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

810 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