Is there a simple method to pull content between a regex? Assume I have the following sample text
SOME TEXT [SOME MORE TEXT] value="ssss" SOME MORE TEXT
My regex is:
compiledRegex = re.compile('\[.*\] value=("|\').*("|\')')
This will obviously return the entire [SOME MORE TEXT] value="ssss", however I only want ssss to be returned since that's what I'm looking for
I can obviously define a parser function but I feel as if python provides some simple pythonic way to do such a task
value="foo'andvalue='bar"which you almost certainly don't want to do. You should use this instead:r'''\[.*\] value=("|')(.*?)\1'''. Note that using a triple-quoted string obviates the need to escape the "'". Also, it's a good idea to always use raw strings (e.g. r'foo' and r"bar") when dealing with regular expressions in Python.