I need to one give me the string between ~
and ^
.
I have a string like this:
~~~~ ABC ^ DEF ^ HGK > LMN ^
I
Your idea of using a lazy quantifier is good, but that still doesn't necessarily give you the shortest possible match - only the shortest match from the current position of the regex engine. If you want to disallow the start/end separators from being part of the match, you need to explicitly exclude them from the list of valid characters. A negated character class comes in handy here.
target = ' ~~~~ ABC ^ DEF ^ HGK > LMN ^ '
matches = re.findall(r'~([^~^]*)\^', target)
print matches