matching a string to extract substrings for which some function returns true
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Tue Nov 22 06:58:36 EST 2005
On Tue, 22 Nov 2005 16:57:41 +0530, Amit Khemka wrote:
> Hello All,
>
> say you have some string: "['a', 'b', 1], foobar ['d', 4, ('a', 'e')]"
> Now i want to extract all substrings for which
> "isinstance(eval(substr), list)" is "True" .
That's an awfully open-ended question. Is there some sort of structure to
the string? What defines a substring? What should you get if you extract
from this string?
"[[[[[]]]]]"
Is that one list or five?
> now one way is to walk through the whole sample string and check the
> condition,
Yes. Where does the string come from? Can a hostile user pass bad strings
to you and crash your code?
--
Steven.
More information about the Python-list
mailing list