Forums > MaxMSP

Extracting specific data from a string of number and letters. Regexp?

September 30, 2008 | 2:10 am

Hi, I have managed to make Max retrieve SMS messages from my mobile phone using the serial object and this is what I get back –

+CMGL: 2873, "REC UNREAD", "+61439017138"
the text message OK

So my question is how can I extract the words "the text message" from all the other info?
I have been able to use the regexp object with these atributes –
regexp \’(.+)\’
this works but I have to put apostrophes ‘ before and after the text in the message when I send it, which I don’t want to have to do.
I am wondering if I can do something similar but get the text between the " after the number and the OK.

Any ideas would be greatly appreciated!

Cheers Tobi.


September 30, 2008 | 3:21 am

Hi Tobi,

Try this:
regexp ".*\+\d*.\s*(.*) OK"

It looks for a ‘+’ (\+) followed by a list of digits (\d*) followed by another character (.) and some whitespace (\s*) and then captures everything after that but before " OK".

That "followed by another character" part should really match a double quote, but I couldn’t seem to get it to work. I tried putting in a \" but it doesn’t work. Anyone know why?

Anyway, that regular expression seems to work. Here’s a patch demonstrating:

– Pasted Max Patch, click to expand. –

September 30, 2008 | 4:10 am

Thanks you very much, works excellently!


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