substitute multiple numbers

Apr 4, 2013 at 3:11pm

substitute multiple numbers

Is it possible to substitute multiple numbers?
So if the combination of 5 6 is found substitute for 5?

#67530
Apr 4, 2013 at 3:21pm

Found it!
regexp (5\s6) @substitute 5

#242993
Apr 5, 2013 at 8:58am

I am using the regexp to substitute numbers. However I am now facing some troubles with number with multiple digits.
How do I address the numbers above 9???

– Pasted Max Patch, click to expand. –
#242994
Apr 5, 2013 at 9:49am

Try this. You don’t want to use character classes, instead use OR (|) matching.

I’d prefer some kind of Max-native solution here, since using regular expressions like this seems messy, but I can’t think of a better way.

Best, Jeremy

– Pasted Max Patch, click to expand. –
#242995
Apr 5, 2013 at 9:57am

the patch you wrote only seems to work with an input message of 3 (or 6 numbers)
how can I alter it, that also the messages with two number work?

#242996
Apr 5, 2013 at 10:00am

a combination of both does the trick:

– Pasted Max Patch, click to expand. –
#242997
Apr 5, 2013 at 12:46pm

That doesn’t really look right to me. In fact, your pattern will substitute more than 3 numbers: 5 7 8 11 12 becomes 3.

You could try this: regexp (5|6|7|8|11)\s(6|7|8|11)((\s(6|7|8|11|12))?) @substitute 3 which uses the ? operator to make the 3rd group optional. But then it won’t match “11 12″, for instance, since it requires a 5, 6, 7, 8,or 11 at the front of the potential list followed by a 6, 7, 8 or 11. So that regexp will match a minimum of 2 and a maximum of 3 numbers in a row.

Regular expressions can do nearly anything related to text processing, in fact, but like any other programming, you have to be really specific about the outcome you desire.

Best, Jeremy

#242998

You must be logged in to reply to this topic.