[Tutor] RE: re

Raymond Hettinger python at rcn.com
Fri Oct 3 22:07:11 EDT 2003


Try this:

    re.split('([A-Z][a-z]*)',word)[1:-1]

The clue is in the docs for re.split() which say, "If capturing
parentheses are used in pattern, then the text of all groups in the
pattern are also returned as part of the resulting list".

Raymond Hettinger

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Kirk Bailey
Sent: Friday, October 03, 2003 9:44 PM
To: Tutor
Subject: [Tutor] RE: re

Regarding re (regular expressions):

%#$^^&*$^@$@!

I am fustrated. I want a function to return a list or a string which is
a 
WikiWord split into words, with the split occuring at the Capitalized
word.

So if I feed it the word ThisIsAWikiWord, it can give me back:
'This Is A Wiki Word'
*OR*
['This','Is','A','Wiki','Word']

Well, I got THIS far...
 >>> def wordsplit(word):
	return re.split('[A-Z]+',word)

 >>> wordsplit(word)
['', 'ary', 'ad', 'ittle', 'amb']
 >>> word
'MaryHadALittleLamb'
 >>>

Please advise. 'Text Processing in Python' is good, but the RE chapter
is not as 
transparent as I would hope. Clue eagerly saught.

-- 

-- 

end

Cheers!
         Kirk D Bailey

  +                              think                                +
   http://www.howlermonkey.net  +-----+        http://www.tinylist.org
   http://www.listville.net     | BOX |  http://www.sacredelectron.org
   Thou art free"-ERIS          +-----+     'Got a light?'-Prometheus
  +                              kniht                                +

Fnord.




_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



More information about the Tutor mailing list