sysctl with regex?
Dag-Erling Smørgrav
des at des.no
Wed Feb 10 11:24:58 UTC 2010
Garrett Cooper <yanefbsd at gmail.com> writes:
> C-shell globs as some programming languages referring to it as,
> i.e. perl (which this is a subset of the globs concept) allow for
> expansion via `*' to be `anything'. Regexp style globs for what you're
> looking for would be either .* (greedy) or .+ (non-greedy), with it
> being most likely the latter case.
Uh, not quite.
Formally, a regular expression is a textual representation of a finite
state machine that describes a context-free grammar.
A glob pattern can be trivially translated to a regular expression, but
not the other way around. Basically, * in a glob pattern corresponds to
[^/]*, ? corresponds to ., and [abcd] and [^abcd] have the same meaning
as in a regular expression. The glob pattern syntax has no equivalent
for +, ?, {m,n}, (foo|bar), etc.
Some shells implement something that resembles alternations, where
{foo,bar} corresponds to (foo|bar), but these are expanded before the
glob pattern. For instance, /tmp/{*,*} is expanded to /tmp/* /tmp/*,
which is then expanded to two complete copies of the list of files and
directories in /tmp.
There is no such thing as a "regexp style glob", and I have no idea what
you mean by "a subset of the globs concept" or where Perl fits into the
discussion.
Finally, .* and .+ are *both* greedy. Perl's regular expression syntax
includes non-greedy variants for both (.*? and .+? respectively).
Note that the [], +, ? and {m,n} notations are merely shorthand for
expressions which can be expressed using only concatenation, alternation
and the kleene star, which are the only operations available in formal
regular expressions.
> I'll see if I can whip up a quick patch in the next day or so -- but
> before I do that, does it make more sense to do globs or regular
> expressions? There are pluses and minuses to each version and would
> require some degree of parsing (and potentially escaping).
I think you'll find that, at least in this particular case, regular
expressions are an order of magnitude harder to implement than glob
patterns.
DES
--
Dag-Erling Smørgrav - des at des.no
More information about the freebsd-hackers
mailing list