Forums > MaxMSP

Calling all regexp experts!

Mar 02 2012 | 8:56 pm

OK, you probably don’t even need to be an expert – just better than me!

I want to detect if an expression includes "Keyboard 2" (without the quotes) – the K can be capitalized or not. "Keyboard 2" may appear at the beginning, middle or end of my expression.

How to??

Mar 02 2012 | 9:03 pm

rename your post as follows:
"calling all Luke Halls"


Mar 02 2012 | 9:21 pm

Yeah, where are you Luke!

So I’ve tried [regexp "K|keyboard 2"] , and that gets me a "keyboard 2" out the substring outlet when I give it an expression that contains "keyboard 2" – so far so good. But then it inappropriately matches a "K" substring for any expression that includes a K….

Mar 02 2012 | 9:24 pm

you want [regexp "[Kk]eyboard 2"]

"K|keyboard 2" – will do a or’ed match of either K and keyboard 2

"[Kk]eyboard 2" – matches a character class (group of characters between []), then the rest of the search (eyboard 2)

Mar 02 2012 | 9:34 pm

That’s it, thanks big_pause!!

Mar 03 2012 | 5:15 pm

Oh man! My Max5 license is still on my old laptop and I can’t afford Max6 on this machine yet so I haven’t been around much. Sorry if you feel I’ve been neglecting you Dan! ;)

Mar 03 2012 | 8:42 pm

No worries Luke, just messing with ya!

Mar 03 2012 | 10:24 pm

i saved every successful use of regexp + i collect these examples from any regexp thread appearing here since i don’t know, a year or two. all in a big patch. this is already helping me so much when i’m stucked again with regexp. because in most cases one example comes at least close to what i want to do. this might be a good tool release one day after they have been categorised a little bit.

Mar 03 2012 | 10:35 pm

There are many online (general) regex test pages out there, a good one is

This has many examples to go through.

Whilst not specific to max, its handy non the less.

Also, you could dive into the Perl regex tutorial, which would help quite a bit

There’ll be more in there than is possible with the max regex object, but it’s all good stuff

Mar 03 2012 | 10:53 pm

yes gskinner is worth a bookmark.

Mar 03 2012 | 11:22 pm

Wow, gskinner is very nice, thanks for that tip big_pause!

Mar 25 2012 | 9:23 pm

OK – follow up to my original question in this thread: now I want to detect when there is a "Keyboard" and a "2" in a symbol. But unlike my previous question, the 2 may not necessarily appear right after the Keyboard; it might appear before, or several words after the Keyboard. How to do with regexp?

Mar 25 2012 | 10:07 pm

Try this for size.

[regexp "[Kk]eyboard.*2|2.*[Kk]eyboard"]

Mar 26 2012 | 3:01 pm

Thank you again! So that *almost* works – it doesn’t however match something like "Trackpad/Keyboard 2", which it should. So I changed your suggestion to [regexp .*[Kk]eyboard.*2|2.*[Kk]eyboard] and it seems to work…

The thing I wasn’t familiar with is the "." – does that mean any character or space? I know that the following "*" means "zero or more occurrences of the preceding character."

Mar 26 2012 | 5:49 pm

The .dot. means anything but a line break, which you shouldn’t have to worry about in this case so your example should work just fine.

Mar 26 2012 | 6:12 pm

Cool, thanks Luke.

Mar 26 2012 | 7:32 pm

you shouldn’t need that .* that you’ve added

see this for eg

-- Pasted Max Patch, click to expand. --

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

Forums > MaxMSP