From owner-freebsd-newbies@FreeBSD.ORG Fri Jan 21 21:20:22 2005 Return-Path: Delivered-To: freebsd-newbies@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8098616A4CF for ; Fri, 21 Jan 2005 21:20:22 +0000 (GMT) Received: from pluto.phpwebhosting.com (pluto.phpwebhosting.com [69.0.209.128]) by mx1.FreeBSD.org (Postfix) with SMTP id EC93A43D2D for ; Fri, 21 Jan 2005 21:20:21 +0000 (GMT) (envelope-from keith@barkinglizards.com) Received: (qmail 5424 invoked from network); 21 Jan 2005 21:20:20 -0000 Received: from unknown (HELO Rand) (69.152.101.1) by pluto.phpwebhosting.com with SMTP; 21 Jan 2005 21:20:20 -0000 From: "Keith Bottner" To: "Freebsd-Newbies@Freebsd. Org" Date: Fri, 21 Jan 2005 15:18:21 -0600 Organization: Barking Lizards Technologies MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 thread-index: AcT//rqlIhXj3/fwTBCSFZAWicO5KQ== Message-Id: <20050121212021.EC93A43D2D@mx1.FreeBSD.org> Content-Type: text/plain; charset="windows-1250" Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.1 Subject: regexec for filtering files in a directory X-BeenThere: freebsd-newbies@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Gathering place for new users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jan 2005 21:20:22 -0000 I am trying to use the regcomp and regexec methods to filter files from a directory; however, the regexec function always says that it matches the pattern. Is there any problems with the regex functions? Or something in the code that I am just missing? Or is there just a better way to do what I am trying to do? Basically: regex_t reg; int err = regcomp(®, "^.+\\.c$", REG_EXTENDED | REG_NOSUB); DIR * dirp = opendir("~/"); struct dirent * pDirEnt; while ((pDirEnt = readdir(dirp)) != NULL) { err = regexec(®, pDirEnt->d_name, 0, 0, 0); if (err == 0) { printf("%s\n", pDirEnt->d_name); } } regfree(&preg); closedir(dirp); Thanks, Keith -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 1/19/2005