ifre_runes[i]=='['&&(i==0||re_runes[i-1]!='\\'){// We do not touch things inside brackets, unless they are escaped
re_postfix[len(re_postfix)-1]=LBRACKET// Replace the '[' character with LBRACKET. This allows for easier parsing og all characters (including opening and closing brackets) within the character class
invertMatch:=false
toAppend:=make([]rune,0)// Holds all the runes in the current character class
ifi<len(re_runes)-1&&re_runes[i+1]=='^'{// Inverting class - match everything NOT in brackets
i+=2// Skip start and hyphen (end will automatically be skipped on next iteration of loop)
continue
}
re_postfix =append(re_postfix,re_runes[i])
toAppend =append(toAppend,re_runes[i])
}
continue
// Replace the last character (which should have been ']', with RBRACKET
toAppend[len(toAppend)-1]=RBRACKET
ifinvertMatch{
toAppend=setDifference(dotChars(),toAppend)// Take the inverse of the set by getting the difference between it and all dot characters
toAppend=append(toAppend,RBRACKET)// Since RBRACKET doesn't exist in dotChars, it wouldn't have been return in setDifference. We manually append it here.
}
re_postfix=append(re_postfix,toAppend...)
}
if(re_runes[i]!='('&&re_runes[i]!='|'&&re_runes[i]!='\\')||(i>0&&re_runes[i-1]=='\\'){// Every character should be concatenated if it is escaped