My 2 cent is that while no doubt this will work for most cases for you: > \+CMGL: (\d+),"(.+)","(\d+)",("(.*)")*,"(.+),(\d+),(\d+) if you absolutely want to be sure it will not capture the quotation mark, then you should modify it like: \+CMGL: (\d+),"([^"]+)","(\d+)","([^"]*)"*,"([^"]+)",(\d+),(\d+) ....so basically you match characters other than quotation marks, instead of just any chars including quotation marks... Also it is a good practice to limit the search area. Regex is greedy, and in some extreme case it can search forever and cause very weird situations. For example if the input is not formatted in the way you expect you can have this problem very easily. So for example if something goes wrong with the input (your GSM modem has a firmware bug), and the line looks like this= : +CMGL: 1,"REC READ","2030",,"13/01/22,11:10:03+00",129,1444444444444444444444444444444444= 444444444444444444444444444444444 .... and so on ... then the regex engine will keep slurping the numbers until out of memory or you kill the process. Because of that, instead of using * or + you can use {} like this: \+CMGL: (\d{1,5}),"([^"]{1,30})","(\d{1,5})","([^"]{0,5})","([^"]{1,30})",(\d{1,5})= ,(\d{1,5}) Note 1: Some regex syntax needs to escape the {} brackets so you might need to write \{1,5\} instead Note 2: I have not really analyze the situation, so you might want to review the limitations I used PS: There are several regex debuggers helping to construct a reliable regex, for example this online tool: http://www.myregextester.com/index.php Tamas On 24 January 2013 07:31, Michael Rigby-Jones < Michael.Rigby-Jones@oclaro.com> wrote: > > > > -----Original Message----- > > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behal= f > > Of Isaac Marino Bavaresco > > Sent: 24 January 2013 14:34 > > To: Microcontroller discussion list - Public. > > Subject: Re: [OT] Regex help > > > > Em 24/01/2013 11:11, Isaac Marino Bavaresco escreveu: > > > This should do: > > > > > > \+CMGL: (\d+),"(.+)","\d+","*(.*)"*,"(.+),(\d+),(\d+) > > > > > > > > > Best regards, > > > > > > Isaac > > > > > > Oops! The closing quote wasn't removed and I forgot the capture group f= or > > the first numeric group > > > > This works: > > > > \+CMGL: (\d+),"(.+)","(\d+)",("(.*)")*,"(.+),(\d+),(\d+) > > > > > > It creates an additional capture group that that you must ignore. > > Your results are in \1, \2, \3, \5, \6, \7 \8 > > > > \4 contains the name with quotes and \5 contains the name without quote= s > > or is empty. > > > > > > Best regards, > > > > Isaac > > Thanks Isaac, that for me exactly as you described. > > Cheers > > Mike > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > This e-mail is intended for the person it is addressed to only. The > information contained in it may be confidential and/or protected by > law. If you are not the intended recipient of this message, you must > not make any use of this information, or copy or show it to any > person. Please contact us immediately to tell us that you have > received this e-mail, and return the original to us. Any use, > forwarding, printing or copying of this message is strictly prohibited. > No part of this message can be considered a request for goods or > services. > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .