如何在python中理解re.sub(“”,“-”,“ abxc”)

时间:2018-08-01 07:11:23

标签: python regex

最近,我学习python regex,我听不懂某些表达式

# but i think it should be : a-b---c
sub_1 = re.sub("x*", "-", "abxc")    # result is : -a-b-c-

# but i think it should be : a-b-x-c
sub_2 = re.sub("", "-", "abxc")      # result is : -a-b-x-c-

# but i think it should be : ['a', '']
find_all_1 = re.findall("a*", "ab")  # result is : ['a', '', '']

# but i think it should be : ['', '', '']
find_all_2 = re.findall("", "abc")   # result is : ['', '', '', '']

0 个答案:

没有答案