regex \b behaviour in python

André Malo auch-ich-m at g-kein-spam.com
Thu Jun 19 15:46:50 EDT 2008


* Walter Cruz wrote:

> irb(main):001:0>"walter ' cruz".split(/\b/)
> => ["walter", " ' ", "cruz"]
> 
> and in php:
> 
> Array
> (
>     [0] =>
>     [1] => walter
>     [2] =>  '
>     [3] => cruz
>     [4] =>
> )
> 
> 
> But in python the behaviour of \b is differente from ruby or php.

My python here does the same, actually:

$ cat foo.py
import re

x = "walter ' cruz"
s = 0
r = []
for m in re.finditer(r'\b', x):
    p = m.start()
    if s != p:
        r.append(x[s:p])
        s = p

print r

$ python2.4 foo.py
['walter', " ' ", 'cruz']
$ python2.5 foo.py
['walter', " ' ", 'cruz']
$

nd
-- 
$_=q?tvc!uif)%*|#Bopuifs!A`#~tvc!Xibu)%*|qsjou#Kvtu!A`#~tvc!KBQI!)*|~
tvc!ifmm)%*|#Qfsm!A`#~tvc!jt)%*|(Ibdlfs(~  # What the hell is JAPH? ;
@_=split/\s\s+#/;$_=(join''=>map{chr(ord(  #             André Malo ;
$_)-1)}split//=>$_[0]).$_[1];s s.*s$_see;  #  http://pub.perlig.de/ ;



More information about the Python-list mailing list