Date: Wed, 10 Feb 2010 12:24:57 +0100 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Garrett Cooper <yanefbsd@gmail.com> Cc: Andrew Brampton <brampton+freebsd@gmail.com>, freebsd-hackers@freebsd.org Subject: Re: sysctl with regex? Message-ID: <86fx59jpti.fsf@ds4.des.no> In-Reply-To: <26049703-8844-4476-B277-776A4EFC0A53@gmail.com> (Garrett Cooper's message of "Tue, 9 Feb 2010 16:14:12 -0800") References: <d41814901002091308s7e894b55p880bde165bbbe703@mail.gmail.com> <86tytqvwky.fsf@ds4.des.no> <d41814901002091528i4884987cmb7347dfe4d50bdc5@mail.gmail.com> <26049703-8844-4476-B277-776A4EFC0A53@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Garrett Cooper <yanefbsd@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 --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86fx59jpti.fsf>