Regexp question

May 25, 2012 at 11:30pm

Regexp question

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!

#57037
May 26, 2012 at 12:48am

Are x y z numbers too?

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

– Pasted Max Patch, click to expand. –
#204387
May 26, 2012 at 12:50am

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

– Pasted Max Patch, click to expand. –
#204388
May 26, 2012 at 2:28pm

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

#204389
May 26, 2012 at 4:24pm

Have a look at [zl stream].

#204390
May 26, 2012 at 5:21pm

@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!

#204391
May 26, 2012 at 6:50pm

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

#204392
May 26, 2012 at 6:55pm

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!

#204393
May 26, 2012 at 7:16pm

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.

#204394
May 26, 2012 at 8:40pm

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.

a wild guess:

– Pasted Max Patch, click to expand. –
Attachments:
  1. zltest.maxpat
#204395
May 26, 2012 at 10:13pm

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

– Pasted Max Patch, click to expand. –
#204396
May 27, 2012 at 2:51pm

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!

[attachment=195042,3961]

Attachments:
  1. Screenshot20120527at10.45.25AM.png
#204397
May 27, 2012 at 2:59pm

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

#204398
May 27, 2012 at 7:10pm

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

– Pasted Max Patch, click to expand. –
#204399
May 27, 2012 at 7:36pm

Thanks – literally just solved it a slightly different way.

appreciate the help!!!

– Pasted Max Patch, click to expand. –
#204400
May 28, 2012 at 5:37am

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

– Pasted Max Patch, click to expand. –
#204401
May 28, 2012 at 3:30pm

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

cheers!

#204402

You must be logged in to reply to this topic.