[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Regular Expressions

Posted on 2003-11-27
3
Medium Priority
?
310 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 375 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

650 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