Solved

Regular Expressions

Posted on 2003-11-27
3
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

707 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