### Re: Detect STX and ETX hex in received string

by kcott (Chancellor)
 on Nov 28, 2012 at 07:28 UTC ( #1005970=note: print w/replies, xml ) Need Help??

G'day jagexCoder,

Welcome to the monastery.

This regexp seems to do what you want:

```qr{ [\$STX] ( [^\$ETX]{0,80} ) [^\$ETX]* [\$ETX] }x

Here's my test:

```\$ perl -Mstrict -Mwarnings -e '
my (\$STX, \$ETX) = (chr(2), chr(3));
my \$re = qr{ [\$STX] ( [^\$ETX]{0,80} ) [^\$ETX]* [\$ETX] }x;
my \$empty = \$STX . \$ETX;
my \$short = \$STX . "a" x 79 . \$ETX;
my \$exact = \$STX . "a" x 80 . \$ETX;
my \$long = \$STX . "a" x 81 . \$ETX;
my \$buf = \$empty . \$short . \$exact . \$long;
print "1234567890" x 8, "\n";
print "\$_\n" for \$buf =~ /\$re/g;
print "1234567890" x 8, "\n";
'
1234567890123456789012345678901234567890123456789012345678901234567890
+1234567890

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaa
1234567890123456789012345678901234567890123456789012345678901234567890
+1234567890

-- Ken

Replies are listed 'Best First'.
Re^2: Detect STX and ETX hex in received string
by ColonelPanic (Friar) on Nov 28, 2012 at 09:05 UTC

This regex would not match anything unless an ETX was found, while the poster wanted to stop reading as soon as 80 bytes were found.

(Apologies; originally this comment contained a typo such that it made no sense)

When's the last time you used duct tape on a duct? --Larry Wall

I'd say that's a matter of interpretation. I did consider the situation where no ETX existed; however, jagexCoder wrote "... packets of interest that are within STX and ETX endings.". Accordingly, I coded for STX and ETX to always be present. Perhaps wait for the OP to clarify this.

[Aside: You appear to have removed the original typo, so I don't know what you're apologising for. Regardless, I accept your apology. :-) ]

Update: Oh dear! Having posted this, I see I've also introduced a typo such that it made no sense.
s/Perhaps wait for to OP can clarify this./Perhaps wait for the OP to clarify this./

-- Ken

Fair enough, I suppose it is a matter of interpretation.

When's the last time you used duct tape on a duct? --Larry Wall

Create A New User
Node Status?
node history
Node Type: note [id://1005970]
help
Chatterbox?
 thezip switches the jolokia powder with Folgers Crystals... [Michael W]: So i can read ok from this how do i put data back inmy @Variables = ( \$Map_Request_Date, \$Map_Due_Date,\$Map _Cutover_Date,\$Map _Complete_Date,\$Ma p_Approved_Date); [Corion]: Michael_W: \$Variables[0] = \$Map_Request_Date; \$Variables[1] = \$Map_Due_Date; ... [choroba]: ( \$Map_Request_Date, \$Map_Due_Date,\$Map _Cutover_Date,\$Map _Complete_Date,\$Ma p_Approved_Date) = @Variables;? [thezip]: something like: \$Map_Request = ; etc. should work [Corion]: Duh - I read it backwards. I shouldn't code today I guess ;)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-04-27 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I'm a fool:

Results (509 votes). Check out past polls.