While splitting String I found different result using regex. Consider the following examples -
- using string.split()gives me alistexcluding the delimiter-.
var3 = "black.white"
print(var3.split('.'))
# result
# ['black', 'white']
- using re.split()using this regex-([.] *)gives me alistincluding the delimiter -.
var3 = "black.white"
print(re.split('([.] *)', var3))
# result
# ['black', '.', 'white']
- using re.split()with this regex-[.] *without the grouping parenthesis()gives me alistexcluding the delimiter -.
var3 = "black.white"
print(re.split('[.] *', var3))
# result
# ['black', 'white']
I know there is something to do with the grouping parenthesis () but couldn't understand why. Therefore I have these three question in mind -
- Why string.split()doesn't keep the delimiter
- Why re.split()keeps the delimiter
- Why grouping parenthesis ()inregexmakes the difference
note: I am new to python and regex
 
     
    