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

  • Home
  • SEARCH
  • 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 3398042
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:36:05+00:00 2026-05-18T04:36:05+00:00

Calling regex gurus. I’m having some trouble right now with escaping a string in

  • 0

Calling regex gurus. I’m having some trouble right now with escaping a string in Ruby so that I can pass it into a command line utility using exec, %x{} or similar. The command line command is the TextMate dialog feature, which basically works like this (Run this as a shell script in TextMate.):

$DIALOG -mp "items=('string1','string2', 'string3');" RequestItem

but it can also use a nib file you specify like “path/to/my/nib/file.nib” So, I need to pass that whole command as a string to exec

command = <<string
$DIALOG -mp "items=('string1','string2', 'string3');" "path/to/my/nib/file.nib"
string
exec command

This works fine naturally. The problem that I am running into is that the components of the items array are determined programmatically, so I need to programmatically escape this string in a way that will pass it all to the $DIALOG command properly.

So far, I have determined a need to escape single quotes, double quotes, and newline and tab characters. I’ve tried a ton of potential regular expression solutions but haven’t yet been able to land on a reliable escaping mechanism. Basically, I need to fill in

class String
    def escape_for_dialog
        self
    end
end

with the right self.gsub calls that will escape the strings that I am putting into the parameters. So, let’s assume my params are looked up at runtime, here’s what I think I need to do using the same example above:

command = <<string
$DIALOG -mp "items=('#{item1.escape_for_dialog}', '#{item2.escape_for_dialog}', '#{item3.escape_for_dialog}');" "path/to/my/nib/file.nib"
string
exec command

I have figured out that the heredoc style helps with not having to remember to escape all the quotes, but the parameters are still problematic so I’m asking for someone better with string manipulation and regular expressions than I am to lend a hand at filling in that string method. I’ll be most grateful! 🙂

  • 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-05-18T04:36:06+00:00Added an answer on May 18, 2026 at 4:36 am

    Sadly, the answer to this is much simpler than it would seem: TextMate has a Ruby method for it! TextMate.app/Contents/SharedSupport/Support/lib#e_sh

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

Sidebar

Related Questions

Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function
Calling all C macro gurus... Is there any way to write a C macro
When calling CoInitializeEx , you can specify the following values for dwCoInit : typedef
Calling TextView.setTextSize() is working abnormally. Right after the call to setTextSize if we get
Calling the javascript gurus out there. Basically my question is regarding how you structure
I'm a bit worried about performance issue when calling RegEx.Replace to really big amount
Possible Duplicate: How to decode string to XML string in C# I'm calling a
Here's my problem. I am calling a service that is returning several identical nodes
When calling a remote service (e.g. over RMI) to load a list of entities
When calling php via cli, the current directory is NOT changed to the one

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.