From: Matt Brooks Date: 2009-10-29T22:14:47+09:00 Subject: Re: String Matching Problem I appreciate everyone's input, It seems like they should all work, and do, initially, but for my application each one seems to stop working for another reason.... I am checking tons of messages, actually I am searching a buffer of messages, about 600 messages, every time a message is received, so if it takes to long to search the buffer, the new received messages start piling up I guess and don't ever get in the buffer to be searched, and so on, it is a vicious cycle I guess. I think each of these ways takes too many resources, compared to line[cmd], where line is my line received and cmd is the initial match I am looking for. I suppose line[cmd] is really optimized for quick checking. I tried every way you all listed, and it works for a few messages, then it seems to get bogged down and miss messages or something as the buffer fills up and gets larger and larger to check each one in the buffer. Even the one liner, line[/\A#{cmd}(\z|,)/], stops working pretty quick. Odd problem, because when I throw my regular line[cmd] code in there, it works like a charm continuously, except at the corner cases that provoked this thread to start with, "the unavoidable partial match". Hate to ask again, any more less intensive ways to do it? It will be ran up to 600 times every tenth of a second probably. Keep in mind sometimes, it only has to search the buffer for the first 10 or so messages before it finds a match, but sometimes it must go all the way deep into the buffer 500 or so to get a match, then it starts on the next one... etc.. the code, with check and match_prefix methods defined as above posts... i = 0 #iterate through buffer looking for message while(i < @message_buffer.num_in_buf) if found_message == false line = @message_buffer.get(i) #if check(line,cmd) #resource hog #if line[/\A#{cmd}(\z|,)/] #resource hog #if(line.match_prefix(cmd)) #resource hog if line[cmd] if ((cmd != "SDRI") and (cmd != "SDRL") and (cmd != "CHLL")) write_log("<- #{@message_buffer.get(i)}",1)#DEBUG write_log("="*15 + "Ascii Response Message: #{cmd} Received" + "="*10 + "\n") found_message = true break #message was found, don't search buffer anymore end end # if this line has the cmd end i += 1 #check next message in buffer end # while whole buffer -- Posted via http://www.ruby-forum.com/.