From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 10 17:23:02 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BA52A106566B for ; Wed, 10 Feb 2010 17:23:02 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-pz0-f202.google.com (mail-pz0-f202.google.com [209.85.222.202]) by mx1.freebsd.org (Postfix) with ESMTP id 8DA8A8FC15 for ; Wed, 10 Feb 2010 17:23:02 +0000 (UTC) Received: by pzk40 with SMTP id 40so236505pzk.7 for ; Wed, 10 Feb 2010 09:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=NVQaIXgm8UKvQEOP+xkaq1cIAnHIrq3tqkCU3nGoafQ=; b=OCLfmTz/GfigjdHYvVCgR7Hb6Wew5nkaj8G4IoNnL/gP0IWrwn22R1MIiBywLwb0gl ako/uqM+00WsI+yisDSKyw6b2WpAnWvrPIz8bldm5FLqF+dWZy5CLVs+QDnT5Tv7dMiS TYCWcLbTJRHqHF5+5he1ix7SMECmdotkMfaHw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=c1wxiprWHlPOOi2Al7hNk39zureqoDmeFVtHxrQdihz05I+WRcBOCKrTDBybYKo59v WLjQc8UuHw+LtyxvWUQ+q+E2S057WdjQKHeN91ZlHgntmGGJTCJM5f5UY3VU3iJFNU/q FZiyIYnv/cViTgOFNbju2YWiOgjC1UwlqnwjM= MIME-Version: 1.0 Received: by 10.142.60.2 with SMTP id i2mr328611wfa.143.1265822581970; Wed, 10 Feb 2010 09:23:01 -0800 (PST) In-Reply-To: <86fx59jpti.fsf@ds4.des.no> References: <86tytqvwky.fsf@ds4.des.no> <26049703-8844-4476-B277-776A4EFC0A53@gmail.com> <86fx59jpti.fsf@ds4.des.no> Date: Wed, 10 Feb 2010 09:23:01 -0800 Message-ID: <7d6fde3d1002100923i6bbc24a7ocaf408f4d78ec59f@mail.gmail.com> From: Garrett Cooper To: =?ISO-8859-1?Q?Dag=2DErling_Sm=F8rgrav?= Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Andrew Brampton , freebsd-hackers@freebsd.org Subject: Re: sysctl with regex? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Feb 2010 17:23:02 -0000 2010/2/10 Dag-Erling Sm=F8rgrav : > Garrett Cooper 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. =A0Basically, * in a glob pattern corresponds t= o > [^/]*, ? corresponds to ., and [abcd] and [^abcd] have the same meaning ^^^^ ???? ^^^^ The former is a positive assertion, where the latter is a negative assertion -- how can they have the same meaning? > as in a regular expression. =A0The glob pattern syntax has no equivalent > for +, ?, {m,n}, (foo|bar), etc. +, {}, and () -- no... that's typically an extension to shell expanded values (IIRC). ? however, is a supported glob quantifier [from glob(3)]: The argument pattern is a pointer to a pathname pattern to be expanded= . The glob() argument matches all accessible pathnames against the patte= rn and creates a list of the pathnames that match. In order to have acce= ss to a pathname, glob() requires search permission on every component of= a path except the last and read permission on each directory of any file= - name component of pattern that contains any of the special characters `*', `?' or `['. > Some shells implement something that resembles alternations, where > {foo,bar} corresponds to (foo|bar), but these are expanded before the > glob pattern. =A0For 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. This is what I'm referring to: http://perldoc.perl.org/functions/glob.html . Semantically I was wrong in areas in my original statement, but I was trying to hand wave from a basic `I don't know how globs vs regexps work', without the technical lexigram discussion. > Finally, .* and .+ are *both* greedy. =A0Perl's regular expression syntax > includes non-greedy variants for both (.*? and .+? respectively). Yes, but I didn't explicitly note those forms. > 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. Yes... I wholeheartedly agree... Thanks :), -Garrett