Preg quotes

Back porting @AlexanderOMara's fix to the 1.0.2 patch, plus some more missing or wrong delimiters found in preg_quotes around the code.