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 8221195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:49:19+00:00 2026-06-07T13:49:19+00:00

Let’s say I have: <cfscript> arrButtons = [ { name = Add, bclass =

  • 0

Let’s say I have:

<cfscript>
arrButtons = [
    {
        "name" = "Add",
        "bclass" = "add",
        "onpress" = "addItem"
    },
    {
        "name" = "Edit",
        "bclass" = "edit",
        "onpress" = "editItem"
    },
    {
        "name" = "Delete",
        "bclass" = "delete",
        "onpress" = "deleteItem"
    }
];

jsButtons = SerializeJSON(arrButtons);
// result :
// [{"onpress":"addItem","name":"Add","bclass":"add"},{"onpress":"editItem","name":"Edit","bclass":"edit"},{"onpress":"deleteItem","name":"Delete","bclass":"delete"}]
</cfscript>

For every onpress item, I need to remove the double quotes from its value to match the JS library requirement (onpress value must a callback function).

How do I remove the double quotes using a regular expression?

The final result must be:

[{"onpress":addItem,"name":"Add","bclass":"add"},{"onpress":editItem,"name":"Edit","bclass":"edit"},{"onpress":deleteItem,"name":"Delete","bclass":"delete"}]

No double quotes surrounding addItem, editItem, and deleteItem.

Edit 2012-07-13
Why I need this? I created a CFML function that the result is a collection of JS that will be used in many files. jsButton object will be used as one part of the options available in the JS library. One of that function’s arguments is an array of struct (the default is arrButtons), and the supplied arguments value can merge with the default value.

Since we can’t (in CFML) write onpress value without double quotes, so I have to add double quotes to that value, and convert the (CFML) array of struct to JSON (which is just a string) and remove the double quotes before place it in the JS library option.

with Railo, we can declare the struct as a linked struct to make sure we have same ordered key for loop or conversion (from above example onpress always the latest key in the struct). with this linked struct and same key order, we can remove the double quotes with simple Replace function, but of course we can’t guarantee every programmer who use the CFML function doesn’t forget to use linked struct and key order same as example above

  • 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-07T13:49:20+00:00Added an answer on June 7, 2026 at 1:49 pm

    I’m not sure this is actually necessary – depending on how/where you’re dealing with the JS callbacks, it might be possible to use the string function names to reference the function without needing to remove the quotes (i.e. object[button.onpress]).

    However, since you asked, here is a regex solution:

    jsButtons  = jsButtons.replaceAll('(?<="onpress":)"([^"]+)"','$1');
    

    The regex there is made up of two parts:

    (?<="onpress":) — lookbehind to ensure we are dealing with the text "onpress":
    "([^"]+)" — match the quotes and capture their contents.

    The $1 on the replacement side is to replace the matched text (i.e. the entire quoted value) with the first capture group (i.e. the contents of the quotes).

    If case-sensitivity of “onpress” might be an issue, you can prefix the regex with (?i) to ignore case.

    If there will be multiple different events (not just “onpress”) you can update the relevant part of the expression above to be (?<="on(?:press|hover|squeek)":) etc.

    Note: All the above relies on the format output from serializeJson not changing – if it’s possible that there might be comments, whitespace, single quotes, or anything else in future then a longer expression would be needed to cater for those – which is part of why you should investigate if you even need regex to solve this problem in the first place.

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

Sidebar

Related Questions

Let's say I have window.open (without name parameter), scattered in my project and I
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say I have a table with a Color column. Color can have various
Let's say that I have a SQLite database that I create in a separate
Let's say I have thousands of users and I want to make the passwords
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do

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.