From owner-freebsd-questions Tue Oct 23 18:54:20 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-65-31-203-60.mmcable.com [65.31.203.60]) by hub.freebsd.org (Postfix) with SMTP id E7FEC37B401 for ; Tue, 23 Oct 2001 18:54:16 -0700 (PDT) Received: (qmail 29426 invoked by uid 100); 24 Oct 2001 01:54:16 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15318.8008.241466.858831@guru.mired.org> Date: Tue, 23 Oct 2001 20:54:16 -0500 To: Shill Cc: questions@freebsd.org Subject: Re: regex(3), re_format(7) and shortest match In-Reply-To: <87041511@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Shill types: > >> Say I have the string: > >> "yo hiphop fun" > >> > >> Can anyone tell me how to achieve the shortest match? > >> > >> i.e. the first call to regexec() would return "" > >> and the second would return "". > > > Try this: () > > What if '<' '/' 'a' '>' are all valid characters inside ""? > > i.e. if I have the string "yo hiphop" a call to > regexec() should return " ". > > If I use the () regex, it would just return REG_NOMATCH. Use python re module - or Perl if you must - and then "" will work for your regular expression. The "?" makes the * match the shortest possible string that matches, which is what you want. If you have to invoke it from C, the sources to this can be found in /usr/src/contrib/perl5. Be warned that this is GNU-licensed code, not BSD-licensed code, so check the license restrictions before distributing the source or anything built on it. http://www.mired.org/home/mwm/ Q: How do you make the gods laugh? A: Tell them your plans. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message