[原] Python 取指定定界符中间的内容

# 取指定定界符中间的内容
def mid(content: str, beginString: str = '', endString: str = ''):
    """
    取指定定界符中间的内容
    :param content: str 要截取的字符串
    :param beginString: str 开始定界符
    :param endString: str 结束定界符
    :return: str 子串
    """

    if len(beginString) > 0:
        beginPos = content.find(beginString)
        if beginPos == -1:
            return ''
    else:
        beginPos = -1

    if len(endString) == 0:
        if beginPos == -1:
            return ''
        return content[beginPos + 1:]

    endPos = content.find(endString)
    return content[beginPos + 1:endPos]

你可能感兴趣的:(编程语言,网络与安全,Python/Ruby)