'Find given in expected.
If self.regexp is true, regular expression search is used.
if self.case_insensitive is true, case insensitive search is used, otherwise case sensitive search is used.
Spaces around values of attributes are stripped in XML parsing step.
Args:
expected: list.
given: str.
Returns: bool
Raises: `ResponseError` if it fails to compile regular expression.
Note: for old code, which supports _or_ separator, we add some  backward compatibility handling.
Should be removed soon. When to remove it, is up to Lyla Fisher.'

def check_string(self, expected, given):

    if (not given):
        return False
    _ = self.capa_system.i18n.ugettext
    if self.backward:
        return self.check_string_backward(expected, given)
    if self.regexp:
        flags = (re.IGNORECASE if self.case_insensitive else 0)
        try:
            regexp = re.compile((('^' + '|'.join(expected)) + '$'), flags=(flags | re.UNICODE))
            result = re.search(regexp, given)
        except Exception as err:
            msg = u'[courseware.capa.responsetypes.stringresponse]    {error}:    {message}'.format(error=_('error'), message=err.message)
            log.error(msg, exc_info=True)
            raise ResponseError(msg)
        return bool(result)
    elif self.case_insensitive:
        return (given.lower() in [i.lower() for i in expected])
    else:
        return (given in expected)
