Compare a string with optional characters