Converts String::replace regex function to C