John Machin wrote:
> >>> import re
> >>> text = "(word1 & (Word2|woRd3))".lower()
> # you seem to want downshifting ...
> >>> re.split(r"\W+", text)
> ['', 'word1', 'word2', 'word3', '']
> >>>
>
> Hmmm ... near, but not exactly what you want. We need to throw away
> those empty strings, which
cheng wrote:
> hi all
> a string like
>
> "(word1 & (Word2|woRd3))"
>
> how can i use the re to split it to
>
> ['word1', 'word2', 'word3']
>
OK, so you know about the re module.
Look in the manual: there's a module-level function called
"split", with an example similar to yours. Did you try
"cheng" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
| hi all
| a string like
|
| "(word1 & (Word2|woRd3))"
|
| how can i use the re to split it to
|
| ['word1', 'word2', 'word3']
|
import re
s = "(word1 & (Word2|woRd3)"
parts = re.split('\W+', s)
print [p for p in parts if
thx for help..i got it now :)
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 29 May 2005 at 07:39 GMT, cheng wrote:
> hi all
> a string like
>
> "(word1 & (Word2|woRd3))"
>
> how can i use the re to split it to
>
> ['word1', 'word2', 'word3']
This splits the string on one or more occurrences of any character
that is not alphanumeric:
import re
str = "(
cheng wrote:
> im sorry, my engilsh is not vell well,
That's alright, you could have been french. ;)
> the string not only contain '&' and '|' and it can be anyting
>
> i just want to split out the "whole word" inside the string
Look at the example for split function of re module in the doc [1]
On May 29, 2005, at 12:57 AM, cheng wrote:
> im sorry, my engilsh is not vell well,
>
> the string not only contain '&' and '|' and it can be anyting
>
> i just want to split out the "whole word" inside the string
If the string could be anything, how do you know where the words are?
If it's whi
i try
theString= theString.lower()
print re.split(r'\W+',theString)
the reslut is :
['', 'word1', 'word2', 'word3', '']
how can i fix the statment to get
['word1', 'word2', 'word3']
--
http://mail.python.org/mailman/listinfo/python-list
i try
query = query.lower()
print re.split(r'\W+',theString)
the reslut is :
['', 'word1', 'word2', 'word3', '']
how can i fix the statment to get
['word1', 'word2', 'word3']
--
http://mail.python.org/mailman/listinfo/python-list
im sorry, my engilsh is not vell well,
the string not only contain '&' and '|' and it can be anyting
i just want to split out the "whole word" inside the string
--
http://mail.python.org/mailman/listinfo/python-list
On May 29, 2005, at 12:39 AM, cheng wrote:
> hi all
> a string like
>
> "(word1 & (Word2|woRd3))"
>
> how can i use the re to split it to
>
> ['word1', 'word2', 'word3']
Could you be more exact about what the string is like? Does it
literally contain the characters '&' and '|' ? If so, just
hi all
a string like
"(word1 & (Word2|woRd3))"
how can i use the re to split it to
['word1', 'word2', 'word3']
--
http://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo