I wrote: >> Another nice thing about regexes (as compared to string methods) is >> that they're both portable and serializable. You can use the same >> regex in Perl, Python, Ruby, PHP, etc.
In article <4de9bf50$0$29996$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > Regexes are anything but portable. Sure, if you limit yourself to some > subset of regex syntax, you might find that many different languages and > engines support your regex, but general regexes are not guaranteed to run > in multiple engines. To be sure, if you explore the edges of the regex syntax space, you can write non-portable expressions. You don't even have to get very far out to the edge. But, as you say, if you limit yourself to a subset, you can write portable ones. I have a high level of confidence that I can execute: ^foo/bar on any regex engine in the world and have it match the same thing that my_string.startswith('foo/bar') does. The fact that not all regexes are portable doesn't negate the fact that many are portable and that this is useful in real life. > > You can transmit them over a network > > connection to a cooperating process. You can store them in a database > > or a config file, or allow users to enter them on the fly. > > Sure, but if those sorts of things are important to you, there's no > reason why you can't create your own string-processing language. Apart > from the time and effort required :) The time and effort required to write (and debug, and document) the language is just part of it. The bigger part is that you've now got to teach this new language to all your users (i.e. another barrier to adoption of your system). For example, I'm working with MongoDB on my current project. It supports regex matching. Pretty much everything I need to know is documented by the Mongo folks saying, "MongoDB uses PCRE for regular expressions" (with a link to the PCRE man page). This lets me leverage my existing knowledge of regexes to perform sophisticated queries immediately. Had they invented their own string processing language, I would have to invest time to learn that. As another example, a project I used to work on was very much into NIH (Not Invented Here). They wrote their own pattern matching language, loosely based on snobol. Customers signed up for three-day classes to come learn this language so they could use the product. Ugh. -- http://mail.python.org/mailman/listinfo/python-list