Extracting a parenthesized Python expression from a string
I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form ${expr}, for example, where expr is meant to be a Python expression...
View ArticleAnswer by Edward Z. Yang for Extracting a parenthesized Python expression...
I think your best bet is to match for all curly braced entries, and then check against Python itself whether or not it's valid Python, for which compiler would be helpful.
View ArticleAnswer by Jay for Extracting a parenthesized Python expression from a string
I think what you're asking about is being able to insert Python code into text files to be evaluated. There are several modules that already exist to provide this kind of functionality. You can check...
View ArticleAnswer by Constantin for Extracting a parenthesized Python expression from a...
If you want to handle arbitrary expressions like {'{spam': 42}["spam}"], you can't get away without full-blown parser.
View ArticleAnswer by zaphod for Extracting a parenthesized Python expression from a string
After posting this, reading the replies so far (thanks everyone!), and thinking about the problem for a while, here is the best approach I've been able to come up with:Find the first ${.Find the next }...
View Article