[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Group at several places in string
From: |
Pascal J. Bourguignon |
Subject: |
Re: Group at several places in string |
Date: |
Wed, 13 Jan 2010 01:13:52 +0100 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) |
Johan Andersson <johan.rejeep@gmail.com> writes:
> I have string that contains smaller chunks of text, which are wrapped within
> double quotes. Example:
> Lorem ipsum dolor sit amet, "consectetur" adipiscing elit. Donec "suscipit
> justo" sit amet sem bibendum "sit amet" porttitor mi
> pretium.
>
> I'm looking for a way to add all the chunks in double quotes in a list. So in
> this case:
> '("consectetur" "suscipit justo" "sit amet")
>
> I have created such a function with help of some while loops and whatever
> else. But I thought that it could be done with some regex
> like this "\"\\([^\"]+\\)\"" and then fetch the groupings. But it does not
> work.
>
> How would you solve this?
Here is a simple solution:
(defun parts-in-double-quotes (input)
(loop for sub on (cdr (split-string input "\"")) by (function cddr) collect
(car sub)))
(parts-in-double-quotes "Lorem ipsum dolor sit amet, \"consectetur\" adipiscing
elit. Donec \"suscipit justo\" sit amet sem bibendum \"sit amet\" porttitor mi
pretium.")
--> ("consectetur" "suscipit justo" "sit amet")
--
__Pascal Bourguignon__ http://www.informatimago.com/