From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chris Dennis Newsgroups: gmane.lisp.guile.user Subject: Re: Guile regular expressions are too greedy [Solved] Date: Wed, 22 Jul 2009 16:47:35 +0100 Message-ID: <4A673497.7010008@btinternet.com> References: <4A66E467.2060709@btinternet.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1248277679 16734 80.91.229.12 (22 Jul 2009 15:47:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Jul 2009 15:47:59 +0000 (UTC) Cc: guile-user@gnu.org To: Peter Brett Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 22 17:47:52 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 1MTe2p-0002EF-IE for guile-user@m.gmane.org; Wed, 22 Jul 2009 17:47:51 +0200 Original-Received: from localhost ([127.0.0.1]:52463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTe2p-0005aW-3C for guile-user@m.gmane.org; Wed, 22 Jul 2009 11:47:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTe2h-0005XJ-7a for guile-user@gnu.org; Wed, 22 Jul 2009 11:47:43 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTe2c-0005Vf-PS for guile-user@gnu.org; Wed, 22 Jul 2009 11:47:42 -0400 Original-Received: from [199.232.76.173] (port=51442 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTe2c-0005Va-LE for guile-user@gnu.org; Wed, 22 Jul 2009 11:47:38 -0400 Original-Received: from smtp812.mail.ird.yahoo.com ([217.146.188.72]:42035) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MTe2c-0000fh-9Q for guile-user@gnu.org; Wed, 22 Jul 2009 11:47:38 -0400 Original-Received: (qmail 24869 invoked from network); 22 Jul 2009 15:47:36 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=btinternet.com; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=lO9kX1he9UH3C3wOfZinrySH2A46p21Nv8ussIpHYmQeFxEeV87dclj3F2VjIuTE7Ubu94mv3sTggYD/aK1R2KQtLoA8CTdolQRWnsOl+zOdQkTuLOFKrCe6+qQBlJMD612yObt2Yr7DQr7rgplXN6FEPu9vEU5a86MaciWfc6I= ; Original-Received: from unknown (HELO ?192.168.1.3?) (cgdennis@78.32.16.193 with plain) by smtp812.mail.ird.yahoo.com with SMTP; 22 Jul 2009 15:47:36 -0000 X-Yahoo-SMTP: HmaTfeyswBDGfPXlq_JtxoxwH5.3FMk49vfTMhfMJTiOLKkW X-YMail-OSG: .0mMNuYVM1nWgccM0u0VEDT50317ajBaNaxL6EAF0Kg8n9xgGWWbgTAJ0V7s9tVnnsGuWl5KpsYkyfDqjznfVEMYlrXrO7P1kxj9eio6BCENLc7v27zsazthPW3vFH08I2yNok2uFFDxsdA6Mgv0y9UzaaLklVTXXwjPfMyAb95GGhwf094eNfFhplayR7u.Nuc68zp25PLjDnqrocDjU0XIBRzA3nUI5UV0xUMoSPBlSYFLKxVBQtzogpli49AbVGo5iJwsE6pfBmdcPGo4ZzvnflVimTy6h4ZMKgn5VR1iZFr7ogIkYqiojY47gtpBqJUKiwQlKGtcKj3PRQa4_4dwZymd3iRLSKkAKiF6QYnK X-Yahoo-Newman-Property: ymail-3 User-Agent: Thunderbird 2.0.0.22 (X11/20090608) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: FreeBSD 6.x (1) 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:7371 Archived-At: Peter Brett wrote: > 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 > Brilliant! I was just about to give up on regular expressions and write some tedious string-manipulation code. That works perfectly. Thank you very much. (That code will now become part of GnuCash). cheers Chris -- Chris Dennis cgdennis@btinternet.com Fordingbridge, Hampshire, UK