Forums > MaxMSP

Regexp issue: catching any non-digit (including metacharacters)

January 13, 2014 | 1:57 pm

Hi folks,

I’m hitting a regexp hurdle which is probably quite easily solved (but not for me:).

I need to filter any possible incoming string into either "contains nothing but digits" or "contains even one character that isn’t a digit."

The incoming strings are scene names in Ableton Live, and so might contain anything, including things that Max might interpret as actionable. In my case, Max should simply pass them along as if they were just a block of meaningless text.

I’ve attached a little chunk of patch that I expected would work for the filtering, but which doesn’t. Any ideas?

Thanks,
Dennis

<code>

– Pasted Max Patch, click to expand. –

</code>


January 13, 2014 | 2:47 pm

Hi Dennis :)

if all else fails, look for ascii between 48 and 57?
Andreas (machinate)


January 14, 2014 | 4:11 pm

Hi Andreas!

Interesting idea, that might work.

But I imagine this has got to be simpler than I’m making it…


January 15, 2014 | 4:41 am

In your patch the ‘;’ is actually recognized but overwritten in the output2 message box by a subsequent non-printable carriage return. Filtering this out (ascii 13) gives the intended result.

<code>

– Pasted Max Patch, click to expand. –

</code>


January 15, 2014 | 5:26 am

To filter out "any non-digit including metacharacters" you can use [^\\d] or [^0-9]

To return "contains nothing but digits" you can use [\\d] or [0-9]

[ ] puts em in a bag for you. ^ throws it away. Whatever’s left is returned as a substring via the middle outlet.

Here are a few more.

– Pasted Max Patch, click to expand. –

January 15, 2014 | 6:02 am

Hi folks,

Thanks, these replies are really helpful.

Metamax, your patch is super useful, but I’ve noticed some really interesting results in certain cases. For example:

- the output from [^\\w] when banging the middle message box contains two zeroes. Shouldn’t it contain none?
- Even stranger, the result is *different* depending on what was banged before.
- in all of the cases, the results make less sense when fed very simple input. Feeding them single digits (or simple floats) yields results I don’t understand.

Here’s an example, that’s just your patch with two more simple messages:

<code>

– Pasted Max Patch, click to expand. –

</code>

Thanks,
Dennis


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