There are Regex and there are Regex's. Unfortunately not all implementation= s are compatible with each other. What implementation are you using. -- Bob Ammerman RAm Systems -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Michael Rigby-Jones Sent: Thursday, January 24, 2013 6:18 AM To: Microcontroller discussion list - Public. (piclist@mit.edu) Subject: [OT] Regex help I have been messing around with a GSM modem to send and receive text (SMS) messages and I would like to use a regex expression to parse the string I get when I receive a text message. However, I have very little experience with regular expressions simply because I very rarely need to use them. I am having trouble when it comes to extracting a field that may either be null or could be a quoted string. If it is present, I would like to extrac= t the string without the quotes, or return null if not present e.g. Field of interest is null ( [CR]=3Dcarriage return [LF]=3Dline feed ) +CMGL: 1,"REC READ","2030",,"13/01/22,11:10:03+00",129,14[CR][LF] This is a test[CR] Field of interest is "Fred" though I don't want the actual quotes extracted +CMGL: 1,"REC READ","2030","Fred","13/01/22,11:10:03+00",129,14[CR][LF] This is a test[CR] My regex so far is this (after messing around with 'Expresso' for a while!) \+CMGL: (\d+),"(.+)","(.+)",(.*),"(.+)",(\d+),(\d+)\r\n(.+)\r This mostly works, but if the field is present it extracts the quotes which I don't want, e.g. the capture groups are: 1: 1 2: REC READ 3: 2030 4: "Fred" 5: 13/01/22,11:10:03+00 6: 129 7: 149 8: This is a test So how do I ditch the quotes if they are present? Thanks 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 u= s 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 membershi= p options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .