Solved

Regular Expressions

Posted on 2003-11-27
3
292 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
Comment Utility
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
Comment Utility
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
Comment Utility
Glad to help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now