help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Group at several places in string


From: Johan Andersson
Subject: Re: Group at several places in string
Date: Wed, 13 Jan 2010 08:36:34 +0000

Pascal,

Really cool solution! I have never seen something like it.

Thanks a lot. Tons better than my solution!

On Wed, Jan 13, 2010 at 12:13 AM, Pascal J. Bourguignon <address@hidden> wrote:
Johan Andersson <address@hidden> 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/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]