Forums > MaxMSP

combine->uncombine

November 13, 2008 | 5:24 am

If I combine a list such as hh:mm:ss, how would I then ‘uncombine’ it back into its constituent parts (in this case 3 separate ints, discarding the colons)??
Suggestions?
Thanks
T


November 13, 2008 | 5:50 am

Quote: Terry McDermott wrote on Wed, 12 November 2008 21:24
—————————————————-
> If I combine a list such as hh:mm:ss, how would I then ‘uncombine’ it back into its constituent parts (in this case 3 separate ints, discarding the colons)??
> Suggestions?
—————————————————-

Use regexp

– Pasted Max Patch, click to expand. –

November 13, 2008 | 10:03 am

Perl is one thing (one of many things) I know nothing about. Thanks. You just saved me a large chunk of the evening fooling about with regexp (although I guess I would have learnt something about perl).
Thanks again.
T


November 13, 2008 | 10:47 am

Terry McDermott skrev:
> Perl is one thing (one of many things) I know nothing about. Thanks. You just saved me a large chunk of the evening fooling about with regexp (although I guess I would have learnt something about perl).
> Thanks again.
Unfortunately the Perl documentation is a bit "huh?" when trying to do
those things with regexp… I’m getting to the point where I’d pay good
money for a good hand-holding tutorial website on using the regexp
object. :-)

Andreas.


November 13, 2008 | 10:58 am

Yep, I’m looking at the regexp helpfile right now and thinking …huh…? time to google perl in wikipedia perhaps. must be a simple tutorial out there somewhere…


November 13, 2008 | 5:27 pm

Quote: Terry McDermott wrote on Thu, 13 November 2008 02:58
—————————————————-
> Yep, I’m looking at the regexp helpfile right now and thinking …huh…? time to google perl in wikipedia perhaps. must be a simple tutorial out there somewhere…
—————————————————-

Yeah, there are many tutorials out there and most of them are not very good. This one seems sort of ok: http://www.regular-expressions.info/quickstart.html

You could also try a book like "Teach Yourself Regular Expressions in 10 Minutes" (I haven’t read it, but it seems good for beginners)

Maybe it will help to explain the one I used in that patch:
([^:]*):([^:]*):([^:]*)

[] matches whatever characters are in between the brackets, so [:] matches a colon. When you do [^...] it matches anything EXCEPT what’s in the brackets. So [^:] matches anything other than a colon. The * matches the preceding thing any number of times. That means [^:]* will keep matching characters until there is a colon. Then the : matches the colon. I repeat this pattern to match three sets of non-colon sequences seperated by colons. Finally the (parentheses) will "capture" whatever is between them, and the second outlet of Max’s regexp object outputs all the captured parts as a list.

Regular expressions are not very intuitive, but they are uber-powerful so it is a good thing to learn. Really there are only a few tricks you need to know, like how to use [brackets] (parentheses) and the special symbols . * ? + | ^
It’s just hard to explain in words, unfortunately.


November 13, 2008 | 5:46 pm

I’ve found http://www.regular-expressions.info quite helpful too.

The previous example matches anything between the colons so it would also match "how:are:you:" which shouldn’t really be a problem if you’re only sending it numbers but for the sake of clarity and a mini regular expression lesson here’s what I would use:

regexp ^([0-9]{2}):([0-9]{2}):([0-9]{2})$

[0-9] = matches any numeric character
{2} = match exactly two times
^ = at the start of the string
$ = at the end of the string
(…) = remember as a back reference

So this regexp says: match exactly two numeric characters at the start and remember them, then a colon, then another two numeric characters and remember them, then another colon, then another two numeric characters at the end and remember them. I hope this helps.

lh


November 13, 2008 | 9:47 pm

Thanks Adam & lh; your posts are a great adjunct to the help file. I didn’t end up looking for tutes on the web– turned the computer off and watched a Seinfeld re-run instead– from one form of obscure scripting to another…
T


November 13, 2008 | 9:59 pm

The regexp are definitely powerful but man do they look mysterious. Just mess with them awhile and they’ll start to make sense. You can then do all kinds of interesting stuff with html, for example, as shown in the helpfile.

Along these lines, is there any way to take a single symbol and break it apart, so:

symbol –>
s y m b o l (as a list)

or something like only the third character:

symbol –>
m

?

I know you can do it in Java, and probably jasch’s Strings, but any easy way to do it in regular Max?


November 13, 2008 | 11:40 pm

On 13 nov. 08, at 22:59, Seejay James wrote:

> The regexp are definitely powerful but man do they look mysterious.
> Just mess with them awhile and they’ll start to make sense. You can
> then do all kinds of interesting stuff with html, for example, as
> shown in the helpfile.
>
> Along these lines, is there any way to take a single symbol and
> break it apart, so:
>
> symbol –>
> s y m b o l (as a list)

– Pasted Max Patch, click to expand. –

> or something like only the third character:
>
> symbol –>
> m

– Pasted Max Patch, click to expand. –

You know the funny thing is that each time there’s a question about
regular expression, I more and more feel the same way, there’s no way
you can document such things (apart from the "Mastering Regular
Expression" book, of course). I mean you have to adapt the regular
expression depending on what you need, so obviously everyone needs
something different. But isn’t it why we all use Max after all?

ej


November 14, 2008 | 3:01 am

wow, thanks for that! so simple…


November 14, 2008 | 12:01 pm

Adam Murray schrieb:
> You could also try a book like "Teach Yourself Regular Expressions in
> 10 Minutes" (I haven’t read it, but it seems good for beginners)

The problem with regexp in general for me is, each time I get to them I
have to do the 10 minutes again, they are just the opposite if being
intuitive…;-)

And it is always good to stay in the mood of a beginner, I f I loose it
I try regexp again… ;-)

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


Viewing 12 posts - 1 through 12 (of 12 total)