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

    Jan 13 2014 | 9: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

    • Jan 13 2014 | 10:47 pm
      Hi Dennis :)
      if all else fails, look for ascii between 48 and 57? Andreas (machinate)
    • Jan 15 2014 | 12:11 am
      Hi Andreas!
      Interesting idea, that might work.
      But I imagine this has got to be simpler than I'm making it...
    • Jan 15 2014 | 12:41 pm
      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.
    • Jan 15 2014 | 1:26 pm
      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.
    • Jan 15 2014 | 2:02 pm
      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:
      Thanks, Dennis