* Group at several places in string
@ 2010-01-12 23:23 Johan Andersson
0 siblings, 0 replies; 3+ messages in thread
From: Johan Andersson @ 2010-01-12 23:23 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 636 bytes --]
Hi!
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?
Thanks!
[-- Attachment #2: Type: text/html, Size: 788 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Group at several places in string
[not found] <mailman.1289.1263338646.18930.help-gnu-emacs@gnu.org>
@ 2010-01-13 0:13 ` Pascal J. Bourguignon
2010-01-13 8:36 ` Johan Andersson
0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2010-01-13 0:13 UTC (permalink / raw)
To: help-gnu-emacs
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Group at several places in string
2010-01-13 0:13 ` Group at several places in string Pascal J. Bourguignon
@ 2010-01-13 8:36 ` Johan Andersson
0 siblings, 0 replies; 3+ messages in thread
From: Johan Andersson @ 2010-01-13 8:36 UTC (permalink / raw)
To: Pascal J. Bourguignon; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]
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 <
pjb@informatimago.com> wrote:
> 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/
>
[-- Attachment #2: Type: text/html, Size: 2131 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-13 8:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1289.1263338646.18930.help-gnu-emacs@gnu.org>
2010-01-13 0:13 ` Group at several places in string Pascal J. Bourguignon
2010-01-13 8:36 ` Johan Andersson
2010-01-12 23:23 Johan Andersson
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.