LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filter String using Regular Expression

Hello,

I have an application that monitors serial communication between a PC and device.  The message protocol is a byte stream that I convert to a string to parse into pretty messages.  The start of the string is always "10 02", but if the string is preceded with another "10" like this "10 10 02" it is part of a message.  I've been trying to use a regular expression with the Search and Replace VI.  My regex is "[^10]\s10\s02" which almost works but it cuts off part of the message:

Before:
10 03 10 02

After:
10 0   <= missing the "3"
10 02

Here's what I'm doing:


Any ideas on what I'm missing?  I've attached a simple example.

Thanks


Message Edited by Derek Price on 02-14-2008 08:37 PM
Download All
0 Kudos
Message 1 of 6
(6,133 Views)
[^10] means a character that is neither 1 or 0. I think you want (note: there might be simpiler way to write this),
([^1].|.[^0]) which means not 1 followed by any character or any character followed by not 0.

[^1][^0] won't work since it wouldn't match 15 or 20 for example

If you don't want to through out the characters matched by ([^1].|.[^0]) you can use $1 in the replace string ($1 will hold the value matched by the ([^1].|.[^0]) part of the regex)


Message Edited by Matt W on 02-14-2008 09:11 PM
0 Kudos
Message 2 of 6
(6,123 Views)
Hi Matt,

I tried your regex "([^1].|.[^0])\s10\s02" (no quotes) and I'm actually losing more now.

Before:
10 02 00 00 00 00 10 03 10 02 00 00 10 10 02

After:
10 02 00 00 00 00 10 <= missing 03 now
10 02 00 00 10 10 02

Expecting:
10 02 00 00 00 00 10 03
10 02 00 00 10 10 02


Did I copy the regex correctly?

Thanks
0 Kudos
Message 3 of 6
(6,105 Views)
If you have a byte stream to begin with it would seem to me that it would simply be easier to check the bytes of the byte stream rather than dealing with it after you've converted to a string and having to mess around with regex expressions. Just a suggestion.
0 Kudos
Message 4 of 6
(6,093 Views)
Try this approach.

Do search and replace on '10\s02' and replace with '\r\n10\s20'

Then do another search and replace on '10\r\n\10\s20'  with '10\s10\s20'

See attached.


 
Randall Pursley
Message 5 of 6
(6,086 Views)
Randell - That's perfect!  I didn't think to do the double pass through, but it works great.

smercurio_fc - The data is actually from a text file from Sysinternals Portmon tool, so it's already in text form.

Thanks for all the help!

I still wish I knew regexs better, though...


0 Kudos
Message 6 of 6
(6,074 Views)