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.
How to??
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.
O.
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.
[regexp "[Kk]eyboard.*2|2.*[Kk]eyboard"]
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