From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Peter Brett Newsgroups: gmane.lisp.guile.user Subject: Re: Guile regular expressions are too greedy Date: Wed, 22 Jul 2009 14:41:12 +0100 Message-ID: References: <4A66E467.2060709@btinternet.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1248273047 562 80.91.229.12 (22 Jul 2009 14:30:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Jul 2009 14:30:47 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 22 16:30:40 2009 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MTcq3-0007KS-9j for guile-user@m.gmane.org; Wed, 22 Jul 2009 16:30:35 +0200 Original-Received: from localhost ([127.0.0.1]:58250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTcq2-0001H1-NP for guile-user@m.gmane.org; Wed, 22 Jul 2009 10:30:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTcpg-0000zr-GZ for guile-user@gnu.org; Wed, 22 Jul 2009 10:30:12 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTcpc-0000yf-Iq for guile-user@gnu.org; Wed, 22 Jul 2009 10:30:12 -0400 Original-Received: from [199.232.76.173] (port=42662 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTcpc-0000yZ-EU for guile-user@gnu.org; Wed, 22 Jul 2009 10:30:08 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:36741) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MTcpc-0007z3-2f for guile-user@gnu.org; Wed, 22 Jul 2009 10:30:08 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MTcpb-0004mH-AB for guile-user@gnu.org; Wed, 22 Jul 2009 10:30:07 -0400 Original-Received: from root by ciao.gmane.org with local (Exim 4.43) id 1MTcpW-00031D-Jb for guile-user@gnu.org; Wed, 22 Jul 2009 14:30:02 +0000 Original-Received: from 131.227.8.63 ([131.227.8.63]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Jul 2009 14:30:02 +0000 Original-Received: from peter by 131.227.8.63 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Jul 2009 14:30:02 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 131.227.8.63 User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:zR8WJVEt8YOIPqdkohxeLW+Mw6E= X-Detected-Operating-System: by mx20.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7370 Archived-At: Chris Dennis writes: > Hello Guile People > > Is there a way to make Guile regular expressions less greedy? I > understand that POSIX doesn't define non-greedy modifiers. > > Specifically, I'm trying to parse font names such as > > Arial 12 > Arial Bold Italic 14 > Nimbus Sans L Bold Italic Condensed 11 > > so that I can construct CSS styles from them. > > I've tried the following, but the first (.*) gobbles up everything > before the size because the other elements are optional: > > (define s (string-match "(.*)( +(bold|semi-bold|regular|light))?( > +(italic|oblique))?( +(condensed))? +([0-9]+)" "nimbus sans l bold > italic condensed 11")) > > > Are there other ways of doing this? > Does this work for you? (define (parsefont str) (let ((match (string-match "( +(bold|semi-bold|regular|light))?( +(italic|oblique))?( +(condensed))? +([0-9]+)" str))) (cons (match:prefix match) (map (lambda (n) (match:substring match n)) '(2 4 6 7))))) (parsefont "nimbus sans l bold italic condensed 11") ==> ("nimbus sans l" "bold" "italic" "condensed" "11") HTH, Peter -- Peter Brett Remote Sensing Research Group Surrey Space Centre