LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-09-2002, 04:41 PM   #1
JustinHoMi
Member
 
Registered: Apr 2001
Location: Raleigh, NC
Distribution: CentOS
Posts: 154

Rep: Reputation: 30
help me match this regex line (easy)


Hey. I'm trying to match this line with regex in a perl script:

Example line:
[STATSME] "mona<810><1657282><CT>" "weapon mac10" "shots 68" "hits 6" "headshots 0"

Every line will look like:

[STATSME] "NAMESTUFF" "weapon SOMEWEAPON" "shots NUM1" "hits NUM2" "headshots NUM3"

The bold stuff is what I need to get out of it.

The string I tried (that didn't work) is:

($s_output =~ /^\[STATSME\] "([^"]+)" "weapon ([^"]+)" "shots ([^"]+)" "hits ([^"]+)" "headshots ([^"]+)"$/)

I also tried replacing each ([^"]+) with (.*) and (.+) but no luck. And I tried replacing each space with a \s.
Any ideas as to what I'm doin wrong??

Thanks!!!
Justin

Last edited by JustinHoMi; 03-09-2002 at 04:44 PM.
 
Old 03-15-2002, 10:58 AM   #2
lavelle
LQ Newbie
 
Registered: Mar 2001
Location: Dallas TX
Distribution: RH7.2 RH7.0
Posts: 12

Rep: Reputation: 0
I think you have a whitespace problem, this program works as expected and isn't that different than your regexp:
#!/usr/bin/perl
while (<DATA>)
{
print "name $1 weapon $2 shots $3 hits $4 headshots $5\n"
if /^\[STATSME\]\s*\"([^\"]+)\".+weapon([^\"]+)\".+shots\s(\d+).+hits\s(\d+).+headshots\s+(\d+)/;
}

__DATA__
[STATSME] "mona<810><1657282><CT>" "weapon mac10" "shots 68" "hits 6" "headshots 0"
[STATSME] "lisa<810><1657283><CT>" "weapon flower" "shots 1" "hits 1" "headshots 1"

One thing I did was not trust what was between the quotes so I used the inneffecient .+ as in .+weapon. What I would do if I where you would be to simplify the code and then (in my example) take the if statement down to:
if /^\[STATSME\]\s*\"([^\"]+)/;
then if that works go up to:
if /^\[STATSME\]\s*\"([^\"]+)\".+weapon([^\"]+)/;

So you can see where your regexp starts going of in the weeds.
 
Old 03-15-2002, 12:18 PM   #3
JustinHoMi
Member
 
Registered: Apr 2001
Location: Raleigh, NC
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 30
Thanks for the reply! I'll try that... I'm afraid that might not be the problem though.

After i posted, i tried matching /STATSME/ and even THAT didn't work. The really odd thing is that there were other lines in the logs that had STATSME typed in them, and it DID match those.

I'm kinda baffled

Justin
 
Old 03-15-2002, 12:30 PM   #4
lavelle
LQ Newbie
 
Registered: Mar 2001
Location: Dallas TX
Distribution: RH7.2 RH7.0
Posts: 12

Rep: Reputation: 0
Did you pull the datafile up in something like emacs so you can see if there are some bizzarre characters in the file?
Has the file ever be DOSified? Perhaps you have some sort of line termination problem and the whole file is slurped in with one <> operator.

Perhaps you could do something like this:
less datafile > datafile2 to scrape out the crap.
You are better off not doing this long term.
 
Old 03-15-2002, 12:39 PM   #5
JustinHoMi
Member
 
Registered: Apr 2001
Location: Raleigh, NC
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 30
Well, to make things more confusing... I have the same exact regex line in a different perl script and it works over there with the same logs :-o.

The program doesn't get it's stats from text files... it listens on a port and waits for another program (the halflife engine) to send it data. I *can* have it important logs manually, but I still get the same error.

The OTHER program (that the regex line works in) is similiar, but reads in the text files on it's own. I don't think that has anything to do with it though....

Maybe I'll try:

/S(.*)T(.*)A(.*)T(.*)S(.*)M(.*)E/

Haha. ::sigh:: signs of desperation....

If you're good with perl (and don't mind) I can send you the script and some sample logs. It's simple, it just doesn't make sense why it doesn't work.

Justin
 
Old 03-16-2002, 11:56 AM   #6
lavelle
LQ Newbie
 
Registered: Mar 2001
Location: Dallas TX
Distribution: RH7.2 RH7.0
Posts: 12

Rep: Reputation: 0
Sure you can send me the program and the log file or just the port and IP of the server if it is open. My email address is lavelle at myrdin dot com.
 
Old 03-17-2002, 01:13 AM   #7
kernal
Member
 
Registered: Mar 2002
Location: North Carolina
Distribution: Linux
Posts: 257

Rep: Reputation: 30
Cool

What game is this for?

 
Old 03-17-2002, 01:43 AM   #8
JustinHoMi
Member
 
Registered: Apr 2001
Location: Raleigh, NC
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 30
It's for counter-strike.

Lavelle, the person who wrote the program that creates the lines that I had to parse altered the logging format into something that was easier for me to parse.

I'm still dying to know why I couldn't get the regex to work, but it's not worth the trouble

Thanks for the offer though!

Justin
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
Linux4RegularGuys - EASY FTP setup using vsftpd - READ THIS FOR EASY HELP DropHit Linux - Networking 4 11-25-2004 02:44 PM
PERL editing single line in file with regex indiescene Programming 0 04-14-2004 08:18 AM
Easy way to install GUI from cmd line? r%t Mandriva 2 12-22-2003 02:12 AM


All times are GMT -5. The time now is 04:57 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration