[Python-ideas] string.replace should accept a list as a first argument

Ryan Gonzalez rymg19 at gmail.com
Wed Oct 7 04:19:35 CEST 2015



On October 6, 2015 9:14:54 PM CDT, Random832 <random832 at fastmail.com> wrote:
>Chris Angelico <rosuav at gmail.com> writes:
>
>> On Wed, Oct 7, 2015 at 11:49 AM, Random832 <random832 at fastmail.com>
>wrote:
>>> Not sure how to get around that, other than by creating a general
>>> "structured regex" module, to build a compiled regex from an
>abstract
>>> regex syntax tree rather than a string. Which actually might not be
>the
>>> worst thing in the world. I think there are some Lisp dialects that
>have
>>> something like that.
>>
>> Ooh, I like this idea. Kinda like the difference between building up
>> an SQL statement by escaping all your input, and using a
>parameterized
>> statement.
>
>Not really. My idea was that no string in regex syntax ever exists, but
>instead something like "(?a|b|c)d*" becomes more like this:
>Sequence(Alternate("a","b","c"), Star("d")), which the regex engine
>could then use instead of parsing a string to build a state machine.
>All strings would be literal strings - "a\.b" would become "a.b" and
>"a.b" would become Sequence("a", Dot(), "b")
>
>Then you could just use Alternate(*lst).

Isn't that kind of like PyParsing with a DFA?

...and that's a really cool idea. Completely coincidentally, I've been working on a JIT-ted regex library in C. There's no parser yet, and I was planning on de-exposing the internal structures, but, after reading this, I'll probably just leave it exposed.

>_______________________________________________
>Python-ideas mailing list
>Python-ideas at python.org
>https://mail.python.org/mailman/listinfo/python-ideas
>Code of Conduct: http://python.org/psf/codeofconduct/

-- 
Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity.


More information about the Python-ideas mailing list