[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Issue with regular expressions
From: "Shawn Milochik" <Shawn () Milochik ! com>
Date: 2008-04-30 18:53:16
Message-ID: 2dc0c81b0804301153g343f0f1eg84951d7a5500cb42 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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
[Attachment #5 (text/html)]
My stab at it:<br><br><br>My stab at it:<br><br>#!/usr/bin/env python<br><br>import \
re<div class="Ih2E3d"><br><br>query = ' " some \
words" with and "without quotes \
" '<br><br></div>query = re.sub("\s+", " ", \
query)<br>
<br><br>words = []<br><br>while query.__len__():<br><br> query = \
query.strip()<br> print("Current query value: \
'%s'" % query)<br> print words<br> \
print<br> <br> if query[0] == \
'"':<br>
secondQuote = \
query[1:].index('"') + 2<br> \
words.append(query[0:secondQuot<div id="1flf" class="ArwC7c \
ckChnd">e].replace('"', \
'').strip())<br> query = \
query[secondQuote:]<br> \
<br> else:<br> if \
query.count(" ") == 0 :<br> \
\
words.append(query)<br> \
query = ""<br> \
else:<br> space = \
query.index(" ")<br> \
words.append(query[0:space])<br> \
query = query[space:]<br> \
<br>
print words<br>print query <br></div><br>
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic