Calling all regexp experts!
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.
rename your post as follows:
"calling all Luke Halls"
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….
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)
That’s it, thanks big_pause!!
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! ;)
No worries Luke, just messing with ya!
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.
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
yes gskinner is worth a bookmark.
Wow, gskinner is very nice, thanks for that tip big_pause!
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?
Try this for size.
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."
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.
Cool, thanks Luke.
you shouldn’t need that .* that you’ve added
see this for eg
----------begin_max5_patcher---------- 478.3ocyUFrTaCCDF9rYFdGzniLooVqsIDN0dlq8FCSGYaQPDGIMRJzjR66d sWYaRCPggJxvAaMZ2U696OuR59iOJgVp2HbTx4jKIII22ZIAs0YIYvPBcEeS UC2gARWIbN9BAcRuSuXiGcrTrsTys0D1nuq0JuS9SQmeFLMcvtdsuQ38aMhP soTxUC9Lbe0MR0huaEU9f6774sqkvl0kBxrTbxYSSeXQcERwWgoi9Uqj2LpA 05URUa0P0CCVk0Xn5xa+zo6FZPYXrLz5uO9ntw1gI++H5ZqdAYjSb0VBDcVA YHdRY3.aVbgUwgCV.oTWNRqXyIXdNRlhy5FlmEWLke3vz2r7pkFd8muXnuJ5 8T.z2Lg6+XPQbgUVzgkR7i1D+XVYrRkm7Ei1r17JNl5IPQVN1o.gFlvaH8sP B1SPB3YHQZzIgUrPrwPt7hkW021L8D3WvzS1wxanMZxdO+61pLrsB.bKHvXw ElrmAlE6AyP0nMR0itJDEcmi8PrSu1VM7Q2eGBYGYWKbdoh6kZ0NAw96ftQV WKP+i.sV53kMh5W3e9qVVEeLkU9GSY0UQ3kjEbvkU16Os52BvMl6DVWelCJp 83ja01t4mNILWpByCYt8jj6jCKIu0Bl01W+AN7GSZB -----------end_max5_patcher-----------