|
![](/i/fill.gif) |
On 08/11/2010 05:31 PM, Darren New wrote:
> Invisible wrote:
>> I'd much prefer to see a much bigger separation between what's a
>> literal character and what's a command.
>
> Technically, they're all commands. The letter "s" means "match against
> the letter s." :-)
Well, if you wanted to split hairs, it's the implicit command "match
against a specific character" plus the argument "s". :-P
>> you could probably use it to match against streams of other data, not
>> just characters.
>
> You can.
Not in any regex product I've ever seen. (Although I won't claim to be
an authority on the subject.) Most people seem to equate "regex" with
"shorthand for writing text parsers".
>> A quick inspection of Wikipedia suggests that POSIX ERE involves at
>> least .[]^$()\*{}?+|:, which is 16, not 10. (Still, it's not the
>> thousands it seemed like last time I tried to learn this stuff.)
>
> : and {} and ^ $ aren't original regular expression characters.
> Technically not + either, so I think that's where the 10 come from. The
> rest are short-cuts for what you can already otherwise specify (: + {
> }), or are useful for programming but outside the theory (^$).
So much for theory. Most "regular expressions" out there aren't even
regular. I don't know much about the theory; what I know about is the
actual regex tools that you can actually use.
>> I recall reading somewhere that Perl's "regular expressions" aren't
>> actually regular, and so require exponential time for matching. Truly
>> regular expressions apparently require only linear time.
>
> Correct. And not only exponential time, but memory as well. A regular
> expression is regular because it requires a fixed amount of memory to
> match or reject.
Is that the definition of "regular" then?
>> The other thing I dislike is that people seem to have a tendency to
>> use regexs where they should be using a real parser.
>
> Yes, well, that's because people are stupid, not regexps.
> Only stupid people. Learn regexps, and learn the theory behind them, so
> when the boss asks you to write a parser, you know which one to use.
My boss well never, ever ask me to write a parser. (Mostly because he
doesn't know what one is, or that such a process is actually necessary.)
Regardless, if you're trying to do complicated parsing, you should use
real parser tools, not a regex.
Now if you just want to do a quick wildcard search, then why not? It can
be useful to be able to say, for example, DELETE *.PNG or something. But
by the time you get to the point where your search term is practically a
predicate calculus, you really shouldn't be trying to encode the entire
thing as a flat character string. You should use a real language instead.
Post a reply to this message
|
![](/i/fill.gif) |