Extracting specific data from a string of number and letters. Regexp?
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 –
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!
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:
----------begin_max5_patcher---------- 507.3ocuU08aaBCD+Y3uBK+TWBCgw7U5aUcU6g8kTk1doTMQvdItJXi.iV1p 5+601.KIsMIjfzPhy5Ne93286ty7nsEbtXMsFBtDbGvx5QaKKiIsAqNcKXQ1 57UY0F2fb5uEye.5ztkjtVZLWIZjTfQsaKdSAiuhJMGC0YjQLdqhv6m063uD bIOqfZ14GzJRFOaqfnBbeT76r1ZR9mRZKxgPG0K39sBXM6ulMQH29ucYlLeI iu3mUzbY6AQHrqmC.gCzKQQZoumqG3d8Qdx1VKbFIyPWPWWBRgtSRUOS0BxD W8R8jKbm7Nv29TJbnrVzoyZgGj019cDLXbnYIYbT37FoTvGJWD914KZe467L 9hM43ARlDsDG0KOqTQW+oDl7U8CSu9Ke7ypd4jXripq31atF78ud6MW8gTnV eZDJ.OyCEivIovzJ4x1wJPAstNaAU0szGxULNMWzvkaOabLRCe5MP3MDZYir PPnGjl0sRLEnFWGUjQhCLSlgwmYUnizdyNJ+WSN9mN4reZ37yceTP60RI8si 6j7l.ap9u3laSD012kQpEMU48vp6RD.5eviPqkLdljol713i+N9rjQHTy1dc VJXjRgpL2AATTfqendzO1jAAH2ds8T3FJXU+m.3cDvFsiOGEriDQ3AfnY+WQ T3.PDdDHRo7j8y.NLKNv -----------end_max5_patcher-----------
Thanks you very much, works excellently!