我要對一個字符串做split
代碼如下
import re
x = re.split(r"(?<=,)","a,b,c,")
print x
輸出的結果是:
['a,b,c,']
而我希望的結果是:
['a,','b,','c,']
等效的perl寫法:
use Data::Dumper;
@x = split(/(?<=,)/,"a,b,c,");
print Dumper \@x
結果:
$VAR1 = [
'a,',
'b,',
'c,'
];
認證高級PHP講師
# Note that split will never split a string on an empty pattern match. For example:
>>> re.split('x*', 'foo')
['foo']
>>> re.split("(?m)^$", "foo\n\nbar\n")
['foo\n\nbar\n']
From: Python 2.7.5 documentation "7.2. re — Regular expression operations"
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號