Issue with regular expressions
Shawn Milochik
Shawn at Milochik.com
Wed Apr 30 14:53:16 EDT 2008
My stab at it:
My stab at it:
#!/usr/bin/env python
import re
query = ' " some words" with and "without quotes " '
query = re.sub("\s+", " ", query)
words = []
while query.__len__():
query = query.strip()
print("Current query value: '%s'" % query)
print words
print
if query[0] == '"':
secondQuote = query[1:].index('"') + 2
words.append(query[0:secondQuote].replace('"', '').strip())
query = query[secondQuote:]
else:
if query.count(" ") == 0 :
words.append(query)
query = ""
else:
space = query.index(" ")
words.append(query[0:space])
query = query[space:]
print words
print query
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080430/dc026b65/attachment-0001.html>
More information about the Python-list
mailing list