07-08-2010 09:13 AM
Let's say I have a four byte long input string, consisting of four hex values: 0x03 0x03 0x03 0x03
If I use repetition in a regex string pattern: .{4} it matches true.
Also, if I use backreference in a new regex pattern: (.)\1\1\1 it matches true.
But I want to combine the two. Say that the first byte is a length byte of the following bytes. Then I'd believe it should be possible to do this: (.).{\1}
The thought is that the first byte is stored as "variable" \1, and reused as the repetition counter. So in this case, all four byte strings starting with 0x03 should match true.
But this doesn't work!
What am I doing wrong here? Is this just not possible?
07-09-2010 02:37 AM
No RegEx experts here?
07-09-2010 10:23 AM
07-09-2010 10:35 AM
@ojohnsen wrote:
No RegEx experts here?
I am not an expert, but I play one on this forum. To show something is possible is quick, since you can demonstrate it. To show something is impossible is a bit harder. For now I say, not possible. And you do realize that .{4} will match any four character string, not anything repeated four times, right?
That said, it sounds like you know the format of your string, so perhaps a regex would not be your first choice. You could split a string, read the first byte, then construct a regex like ^(.)\1{length-1} and see if the remainder of the string begins with a value repeated length times.
07-09-2010 03:44 PM
I don't believe you can put a not-integer value after a slash to bring up a backreference. Further, I don't think you can put a string like \1 into an integer spot inside the curly brakets {3}, the engine has no way to decode that reference (which is of course a string) into an integer and then substitute it to get the ref count. Since you are in LabVIEW and not in perl you can use the first string, decode it into length, and then build a string to input into the regex function block replacement text field to check all the others appropriate length.