473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Finding a pattern in a stream?

Is there a good way to find a pattern of bytes/chars in a stream? I've got
a serial port connected to a tcp port. I need to be able to catch a unique
character string in the stream so that I can perform certain functions. For
example, I have a telnet client connected to an Apple II through the serial
port. The user at the telnet terminal is using the BBS running on the Apple
II just like the good ole days of dialup BBS's. I need to be able to catch
a "command string" sent out from the Apple II (like the "+++ATH") that tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?
Nov 21 '05 #1
5 1633
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've got
a serial port connected to a tcp port. I need to be able to catch a unique
character string in the stream so that I can perform certain functions. For
example, I have a telnet client connected to an Apple II through the serial
port. The user at the telnet terminal is using the BBS running on the Apple
II just like the good ole days of dialup BBS's. I need to be able to catch
a "command string" sent out from the Apple II (like the "+++ATH") that tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?

Nov 21 '05 #2
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"? For
example, I wait for a DataArrival event, read from the serial port and pass
the data out the TCP port. Say the string i'm looking for is "+++ATH". So
I read the serial port and receive "<other data>+++A" and then on the next
read of the serial port I get "TH<more data>". Or maybe it could
conceivably be broken up into 3 or more reads. Is this a situation where I
just have to concatenate the current read with the previous read and then
look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?

Nov 21 '05 #3
Terry,
You would need to check each read to see if it contains the characters you
are looking for. Be careful, depending on how you defined the "Read" your
characters may be spread across two reads.
InStr allows you to find a fixed set of characters a "word".

RegEx allows you to find a pattern (a variable set of characters), the Like
operator is a simplified form of RegEx.

For example: The "^\d+$" RegEx pattern says to find the beginning of the
line/string "^" followed by one or more "+" digits "\d", followed by the end
of the line/string "$"
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"?
For example, I wait for a DataArrival event, read from the serial port and
pass the data out the TCP port. Say the string i'm looking for is
"+++ATH". So I read the serial port and receive "<other data>+++A" and
then on the next read of the serial port I get "TH<more data>". Or maybe
it could conceivably be broken up into 3 or more reads. Is this a
situation where I just have to concatenate the current read with the
previous read and then look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?


Nov 21 '05 #4
Yeah, that was my question in the post. What if my characters ARE spread
across two reads? Do I need to concatenate the previous read with the
current read and check for the pattern? Or is there another way?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ua*************@TK2MSFTNGP11.phx.gbl...
Terry,
You would need to check each read to see if it contains the characters you
are looking for. Be careful, depending on how you defined the "Read" your
characters may be spread across two reads.
InStr allows you to find a fixed set of characters a "word".

RegEx allows you to find a pattern (a variable set of characters), the
Like operator is a simplified form of RegEx.

For example: The "^\d+$" RegEx pattern says to find the beginning of the
line/string "^" followed by one or more "+" digits "\d", followed by the
end of the line/string "$"
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"?
For example, I wait for a DataArrival event, read from the serial port
and pass the data out the TCP port. Say the string i'm looking for is
"+++ATH". So I read the serial port and receive "<other data>+++A" and
then on the next read of the serial port I get "TH<more data>". Or maybe
it could conceivably be broken up into 3 or more reads. Is this a
situation where I just have to concatenate the current read with the
previous read and then look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging
up).
Is there a good way to do this?



Nov 21 '05 #5
Terry,
You could concatenate the two reads together, or match as much as the
pattern in the first read, remember how much you did match, then match the
rest in the second read.

I would recommend which ever you understand & are the most comfortable with.
Concatenating the two reads obviously will be easier... Where as depending
on what else you are doing (you already have a "parser") the second might be
easy enough to have the parser just handle...

Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Yeah, that was my question in the post. What if my characters ARE spread
across two reads? Do I need to concatenate the previous read with the
current read and check for the pattern? Or is there another way?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ua*************@TK2MSFTNGP11.phx.gbl...
Terry,
You would need to check each read to see if it contains the characters
you are looking for. Be careful, depending on how you defined the "Read"
your characters may be spread across two reads.
InStr allows you to find a fixed set of characters a "word".

RegEx allows you to find a pattern (a variable set of characters), the
Like operator is a simplified form of RegEx.

For example: The "^\d+$" RegEx pattern says to find the beginning of the
line/string "^" followed by one or more "+" digits "\d", followed by the
end of the line/string "$"
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"?
For example, I wait for a DataArrival event, read from the serial port
and pass the data out the TCP port. Say the string i'm looking for is
"+++ATH". So I read the serial port and receive "<other data>+++A" and
then on the next read of the serial port I get "TH<more data>". Or
maybe it could conceivably be broken up into 3 or more reads. Is this a
situation where I just have to concatenate the current read with the
previous read and then look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging
up).
Is there a good way to do this?




Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters...
1
by: Tristan | last post by:
Im trying to expand a search util by uing regular expression to allow common search criteria such as +-* and phrases "". My understanding of ereg(string pattern, string string, ) is that the...
13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
7
by: Generic Usenet Account | last post by:
I am trying to set up a delimiter character string for the input stream such that the delimiter string is "skipped over" in the input stream. Can someone suggest how to do this with some sample...
1
by: Bill | last post by:
I have strings returned from a config file that contain zero or more name/value pairs using a pattern like "name = value;" I want to extract the value of a given name (passwords, etc.). I want...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
8
by: googlegroups | last post by:
Hi, I need to parse a binary file produced by an embedded system, whose content consists in a set of events laid-out like this: <event 1<data 1<event 2<data 2... <event n<data n> Every...
13
by: kdt | last post by:
Hi, I'm checking to see if you guys may be able to help me with an algorithm for finding patterns. I have around 2000 short sequences (of length 9) that are aligned. I want to be able to extract...
8
by: Slaunger | last post by:
Hi all, I am a Python novice, and I have run into a problem in a project I am working on, which boils down to identifying the patterns in a sequence of integers, for example ..... 1 6 6 1 6 6...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.