need help of RE

Chris F.A. Johnson cfajohnson at gmail.com
Sun May 29 04:09:44 EDT 2005


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 = "(word1 & (Word2|woRd3))"
s = re.sub("[^a-zA-Z0-9]+"," ",str).split()

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>



More information about the Python-list mailing list