combine->uncombine

Nov 13, 2008 at 5:24am

combine->uncombine

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

#40823
Nov 13, 2008 at 5:50am

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. –
#144828
Nov 13, 2008 at 10:03am

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

#144829
Nov 13, 2008 at 10:47am

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.

#144830
Nov 13, 2008 at 10:58am

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…

#144831
Nov 13, 2008 at 5:27pm

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.

#144832
Nov 13, 2008 at 5:46pm

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

#144833
Nov 13, 2008 at 9:47pm

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

#144834
Nov 13, 2008 at 9:59pm

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?

#144835
Nov 13, 2008 at 11:40pm

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

#144836
Nov 14, 2008 at 3:01am

wow, thanks for that! so simple…

#144837
Nov 14, 2008 at 12:01pm

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

#144838

You must be logged in to reply to this topic.