regex \b behaviour in python
walter.php at gmail.com
Thu Jun 19 17:59:27 CEST 2008
Just a simple question about the behaviour of a regex in python. (I
discussed this on IRC, and they suggest me to post here).
I tried to split the string "walter ' cruz" using \b .
In ruby, it returns:
irb(main):001:0>"walter ' cruz".split(/\b/)
=> ["walter", " ' ", "cruz"]
and in php:
 => walter
 => '
 => cruz
But in python the behaviour of \b is differente from ruby or php.
The guys on the IRC pointed me a way to do that: [m.span() for m in
re.finditer(r'\b',"walter ' cruz")], but if fact there's some
differente as it strips the spaces :)
My question is: why \b behaves like this on python? Why it's different
from ruby or php (or even perl, I believe)?
(For the sake of curiosity, I was trying to solve the
http://www.rubyquiz.com/quiz76.html in python. But the question to not
to solve the quiz, but understand why python is different)
More information about the Python-list