On 5/17/06, Dave Cinege <[EMAIL PROTECTED]> wrote: > Very often....make that very very very very very very very very very often, > I find myself processing text in python that when .split()'ing a line, I'd > like to exclude the split for a 'quoted' item...quoted because it contains > whitespace or the sep char. > > For example: > > s = ' Chan: 11 SNR: 22 ESSID: "Spaced Out Wifi" Enc: On' > > If I want to yank the essid in the above example, it's a pain. But with my new > dandy split quoted method, we have a 3rd argument to .split() that we can > spec the quote delimiter where no splitting will occur, and the quote char > will be dropped: > > s.split(None,-1,'"')[5] > 'Spaced Out Wifi' > > Attached is a proof of concept patch against > Python-2.4.1/Objects/stringobject.c that implements this. It is limited to > whitespace splitting only. (sep == None) > > As implemented the quote delimiter also doubles as an additional separator for > the spliting out a substr. > > For example: > 'There is"no whitespace before these"quotes'.split(None,-1,'"') > ['There', 'is', 'no whitespace before these', 'quotes'] > > This is useful, but possibly better put into practice as a separate method?? > > Comments please.
What's wrong with: re.findall(r'"[^"]*"|[^"\s]+', s) YMMV, n _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com