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

Jan 13, 2014 at 1:57pm

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

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>

#278127
Jan 13, 2014 at 2:47pm

Hi Dennis :)

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

#278134
Jan 14, 2014 at 4:11pm

Hi Andreas!

Interesting idea, that might work.

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

#278250
Jan 15, 2014 at 4:41am

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>

#278272
Jan 15, 2014 at 5:26am

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. –
#278274
Jan 15, 2014 at 6:02am

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

#278276

You must be logged in to reply to this topic.