Python Regex, Finding what is in between two substrings -
the regex have right is:
string="hello (fdd()()()()(()(())()))" re.match("%s\s*\((.*?)\)$"%re.escape("hello"), string)
and work well, goal of whatever inside brackets. in case: "fdd()()()()(()(())())"
i make alteration, regex should work test case
"hello (hihihi(((())))hihi) { "
there curly-brace @ end of it. there should curly-brace @ end of given string therefore first test case showed not work anymore (with new regex want).
try looking @ this
hello[any amount of space]([get whatever inside here])[any amount of space]{[any amount of space]
i think using dollar sign causing me problems. not familiar using regex, if can me great. open solution including not limited other python modules, built in python string features, ect.
thanks help,
i think use "hello\s*\((.+)\)\s*{"
import re text = "hello (hihihi(((())))hihi) { " print re.match(r'hello\s*\((.+)\)\s*{', text).group(1)
gives me
hihihi(((())))hihi
you don't need ?
, $
.
Comments
Post a Comment