Regexp question

DRKOSS's icon

hey all - say i have a string of numbers: 32 32 32 32 00 x y z 88 56 46

and i want to grab just x,y and z from that string? the x y z variables change, while the other numbers remain constant, so I'd like to strip those away and be left with x,y and z

how might i set that up using regexp - and is that the best way?

I am assuming it has to do with the backreference outlet.

thanks!

Ben Bracken's icon

Are x y z numbers too?

Max Patch
Copy patch and select New From Clipboard in Max.

You could certainly do it with regexp, but there might be easier ways. Here are two random methods with zl.slice and unjoin:

broc's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Since your input seems a list of numbers I would use simple list operations.

DRKOSS's icon

Thanks for the replies - mighty kind.

I should have been a bit more specific - that string can exist in a march larger string of numbers and yes the variables are all numbers.

I am sending HUI information from Pro Tools to max and want to pull the individual channels names from the stream of numbers that come in. I have identified them manually but would like to learn how to have max pull them out of the stream.

so the patch would need to be able to extract a specific pattern (or actually up to 8 specific patterns) from a long stream of numbers.

cheers

broc's icon

Have a look at [zl stream].

DRKOSS's icon

@broc - thanks - i will check that out. is there a way to tell zl there are variables in the stream?

for example if i feed zl.filter 240 0 0 102 5 0 16 0 VXYZ 247 where VXYZ are the variables (always numbers) can i represent that in the message zl.filter is meant to be filtering?

Basically telling it - grab 240 0 0 102 5 0 16 0 (whatever 4 numbers are here) 247

thanks!

broc's icon

You can use zl.filter only if the variables VXYZ are always different from the given numbers.

DRKOSS's icon

Thanks for the reply - obliged!

The catch is they are not - pro tools is spitting out all kinds of text (via sysex) and i just want to isolate specific strings which are the channel names. So, unfortunately. sometimes the variables in VXYZ will be numbers that appear elsewhere in the stream, however, it will always be exactly 4 variable and always be preceded by the same sequence and followed by the same sequence.

cheers!

broc's icon

Why don't you use [sysexin] for this?
Then you could apply zl.group (for the fixed number of bytes), and zl.slice as mentioned earlier.

DRKOSS's icon

hi - sorry - feeling a bit thick on this - i think i am missing something basic.

I am indeed using sysexin for getting the data

What i don't understand is how to make the zl.group object filter out the string i want.

Max Patch
Copy patch and select New From Clipboard in Max.

a wild guess:

3958.zltest.maxpat
Max Patch
broc's icon
Max Patch
Copy patch and select New From Clipboard in Max.

zl.group needs the length of the sysex message as argument, ie. 13 in your case.

DRKOSS's icon

gotcha - thanks for your help on this!

I understand how that works in your example - but that is assuming that every sysex message coming from protools is in groups of 13 - right?

Problem is that they are many messages coming in various lengths.

When i use zl.group 13 - i can see attached file in the max window:

As you can see each group of 13 isn't always complete as it may include numbers from the previous or next group of 13.

Wondering if my original plan of figuring out how to have Max identify a particular string and grab it from an incoming stream would be the best option - is this possible?

so that it would see 240 0 0 102 5 0 16 0 V X Y Z 247 and extract that.

then i could use z slice to be left with v x y z

THANKS!

3961.Screenshot20120527at10.45.25AM.png
png
DRKOSS's icon

possible to have zl.lookup work with a group of numbers instead of just single numbers?

broc's icon
Max Patch
Copy patch and select New From Clipboard in Max.

If the message length is variable you can trigger the group with the end symbol (247).

DRKOSS's icon

Thanks - literally just solved it a slightly different way.

Max Patch
Copy patch and select New From Clipboard in Max.

appreciate the help!!!

Ben Bracken's icon
Max Patch
Copy patch and select New From Clipboard in Max.

If you want to use regexp, this might work for you:

DRKOSS's icon

Thanks Ben! I figured there must have been a way like that.

cheers!