Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:48:51+00:00 2026-06-12T17:48:51+00:00

I am working in elisp and I have a string that represents a list

  • 0

I am working in elisp and I have a string that represents a list of items. The string looks like

"apple orange 'tasty things' 'my lunch' zucchini 'my dinner'"

and I’m trying to split it into

("apple" "orange" "tasty things" "my lunch" "zucchini" "my dinner")

This is a familiar problem. My obstacles to solving it are less about the regex, and more about the specifics of elisp.

What I want to do is run a loop like :

  • (while (< (length my-string) 0) do-work)

where that do-work is:

  • applying the regex \('[^']*?'\|[[:alnum:]]+)\([[:space:]]*\(.+\) to my-string
  • appending \1 to my results list
  • re-binding my-string to \2

However, I can’t figure out how to get split-string or replace-regexp-in-string to do that.

How can I split this string into values I can use?

(alternatively: “which built-in emacs function that does this have I not yet found?”)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:48:52+00:00Added an answer on June 12, 2026 at 5:48 pm

    Something similar, but w/o regexp:

    (defun parse-quotes (string)
      (let ((i 0) result current quotep escapedp word)
        (while (< i (length string))
          (setq current (aref string i))
          (cond
           ((and (char-equal current ?\ )
                 (not quotep))
            (when word (push word result))
            (setq word nil escapedp nil))
           ((and (char-equal current ?\')
                 (not escapedp) 
                 (not quotep))
            (setq quotep t escapedp nil))
           ((and (char-equal current ?\')
                 (not escapedp))
            (push word result)
            (setq quotep nil word nil escapedp nil))
           ((char-equal current ?\\)
            (when escapedp (push current word))
            (setq escapedp (not escapedp)))
           (t (setq escapedp nil)
            (push current word)))
          (incf i))
        (when quotep
          (error (format "Unbalanced quotes at %d"
                         (- (length string) (length word)))))
        (when word (push result word))
        (mapcar (lambda (x) (coerce (reverse x) 'string))
                (reverse result))))
    
    (parse-quotes "apple orange 'tasty things' 'my lunch' zucchini 'my dinner'")
    ("apple" "orange" "tasty things" "my lunch" "zucchini" "my dinner")
    
    (parse-quotes "apple orange 'tasty thing\\'s' 'my lunch' zucchini 'my dinner'")
    ("apple" "orange" "tasty thing's" "my lunch" "zucchini" "my dinner")
    
    (parse-quotes "apple orange 'tasty things' 'my lunch zucchini 'my dinner'")
    ;; Debugger entered--Lisp error: (error "Unbalanced quotes at 52")
    

    Bonus: it also allows escaping the quotes with “\” and will report it if the quotes aren’t balanced (reached the end of the string, but didn’t find the match for the opened quote).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with a Lucene index, I have a standard document format that looks something
Say I have a line in an emacs buffer that looks like this: foo
I have classes like this public class someList { public string strOne {get; set;}
Working in D3.js, I'd like to select all the elements that match a selector
Working on a simple downloader, that will download a file items in an array.
Working in iOS 5 I have read a list of file names from my
Working with Sharepoint 2010, I have a class that inherits SPPersistedObject with various settings:
I have some elisp files in a project that I want to byte compile
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.