Peter Brett wrote:
Chris Dennis <cgden...@btinternet.com> 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 cgden...@btinternet.com
Fordingbridge, Hampshire, UK