Re: need help of RE

2005-05-29 Thread Steven Bethard
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

Re: need help of RE

2005-05-29 Thread John Machin
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

Re: need help of RE

2005-05-29 Thread vincent wehren
"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

Re: need help of RE

2005-05-29 Thread cheng
thx for help..i got it now :) -- http://mail.python.org/mailman/listinfo/python-list

Re: need help of RE

2005-05-29 Thread Chris F.A. Johnson
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 = "(

Re: need help of RE

2005-05-29 Thread tiissa
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]

Re: need help of RE

2005-05-29 Thread Elliot Temple
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

Re: need help of RE

2005-05-29 Thread cheng
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

Re: need help of RE

2005-05-29 Thread cheng
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

Re: need help of RE

2005-05-29 Thread cheng
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

Re: need help of RE

2005-05-29 Thread Elliot Temple
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

need help of RE

2005-05-29 Thread cheng
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