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
 
Search this Thread
Old 12-01-2003, 03:12 PM   #1
alitrix
Member
 
Registered: Jun 2003
Location: Netherlands, The
Distribution: Ubuntu, Kernel 2.6.7
Posts: 169

Rep: Reputation: 30
Matching with jokers


Hi,

I'm trying to make matches with sscanf() and with jokers as well.
Can somebody help please?

This is the incoming line I want to react on:
\001ACTION slaps <xxxx> with a 2GB log of W2K\001

What I want is, to check if the incoming line is like that AND if yes.. I want the text between the slaps and with in a variable.
Something like this:
Code:
if (sscanf(msg,"\001ACTION slaps %s with a 2GB log of W2K\001", kw))
/* blaat... */

Except this reacts on every line that begins with "ACTION slaps" :'(
It doesn't care if the rest after it is correct or not
 
Old 12-01-2003, 04:27 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
Sounds like what you want is some sort of regular expression. Unfortunately, I haven't worked with any sort of regular expression library in C/C++. Maybe something like flex could help you out as well, though, I've never really done much with lexical analyzers either, except to look at them briefly....

If the "with a 2GB log of W2k\001" is always the same, you could also always just do a strstr to find that portion of the bit you stored in kw from your sscanf, then NULL terminate it temporarily while you copy the %s part into another string.

Anyway, these are just ideas off the top of my head. It's been awhile since I've done much string manipulation in pure C.

Last edited by deiussum; 12-01-2003 at 04:29 PM.
 
Old 12-01-2003, 04:37 PM   #3
alitrix
Member
 
Registered: Jun 2003
Location: Netherlands, The
Distribution: Ubuntu, Kernel 2.6.7
Posts: 169

Original Poster
Rep: Reputation: 30
Yes, correct.
I want to use somekind of Regulair Expressions.

And about your idea, I was thinking that as well, but is that really a smart idea? (let say, 200 lines in 10 sec, sounds a lot for a idea like that..)
 
Old 12-02-2003, 09:19 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
Well, here's another thought... if you know that the end text for what you want will always be the same, just take the strlen - lenOfEndText to find the start index into your string for that ending text (making sure you don't end up with a negative index), then compare the end text with what you want. If it's the same, you know the index range of the string you are looking for.
 
Old 12-02-2003, 11:26 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Have a look at "man fnmatch" and "man glob".
These are functions for filename matching like the shell does, but they should work for normal strings as well.

For real regular expression matching see "man regcomp".
 
Old 12-02-2003, 02:46 PM   #6
alitrix
Member
 
Registered: Jun 2003
Location: Netherlands, The
Distribution: Ubuntu, Kernel 2.6.7
Posts: 169

Original Poster
Rep: Reputation: 30
Tnx voor those functions
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 8 12-18-2013 05:36 PM
Matching with SQL Ephracis Programming 4 12-16-2004 05:09 AM
No Matching Function for Call ! vipinsharma Programming 2 07-05-2004 01:58 PM
Couldn't find matching filesystem ashesh Linux - General 2 05-23-2004 01:18 AM
Problems with matching alitrix Programming 3 11-18-2003 07:24 PM


All times are GMT -5. The time now is 06:09 PM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration