import re


def _strToVal_Regexp(v, regexp, flag=0, excludeStart=[]):
    """Test (and convert) a generic string type, with a check against a regular expression.
    @param v: the literal string to be converted
    @param regexp: the regular expression to check against
    @param flag: flags to be used in the regular expression
    @param excludeStart: array of characters disallowed in the first position
    @return original string
    @raise ValueError: invalid value
    """
    match = re.match(regexp, v, flag)
    if match is None or match.end() != len(v):
        raise ValueError("Invalid literal %s" % v)
    else:
        if len(excludeStart) > 0 and v[0] in excludeStart:
            raise ValueError("Invalid literal %s" % v)
        return v