How Can I Parse Between Strings In Python

title says all, I want to parse between strings using python what should I look for?

Try IronPython? You can use it with the “Pink Block” Scripts

s = "123123STRINGabcabc"

def find_between( s, first, last ):
    try:
        start = s.index( first ) + len( first )
        end = s.index( last, start )
        return s[start:end]
    except ValueError:
        return ""

def find_between_r( s, first, last ):
    try:
        start = s.rindex( first ) + len( first )
        end = s.rindex( last, start )
        return s[start:end]
    except ValueError:
        return ""


print find_between( s, "123", "abc" )
print find_between_r( s, "123", "abc" )

s = the entire string

first = the left characters of what you want
last = The right characters of what you want

2 Likes