• + 2 comments

    allright, the first few is just changing the input into decoded message without any change i.e into "This$#is% Matrix# %!"

    then the print is using re.sub, the sub work like re.sub (a,b,string), then any a occurence in string will be replaced by b

    then r"(?<=\w)([^\w]+)(?=\w)" is the pattern of a, which will be replaced by " " or spaces.

    (?<=...) means if something before something matches the ... in this case \w, means alphanumeric, then it was part of the pattern we want. Example, a&, then the & is part of the pattern we want

    ([^...]+) the ([]) means it was something that we want for our pattern, which in this case is ^\w means not alphanumeric, equivalent to \W (note the upper/lower). the + means that if it happen several times that's also the pattern we want. Example both & and && is what we want.

    (?=...) means that if anything after the pattern is ..., or here it was \w, then the pattern stop there without including the ... part

    he pattern must be alphanumeric, and the part after the pattern must also be alphanumeric, so a&&b, && is our pattern, but a&& or &&b is not our pattern, as it either doesn't start or end with alphanumeric