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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:39:54+00:00 2026-06-02T04:39:54+00:00

I am using HighCharts and am generating script from C# and there’s an unfortunate

  • 0

I am using HighCharts and am generating script from C# and there’s an unfortunate thing where they use inline functions for formatters and events. Unfortunately, I can’t output JSON like that from any serializer I know of. In other words, they want something like this:

"labels":{"formatter": function() { return Highcharts.numberFormat(this.value, 0); }}

And with my serializers available to me, I can only get here:

"labels":{"formatter":"function() { return Highcharts.numberFormat(this.value, 0); }"}

These are used for click events as well as formatters, and I absolutely need them.

So I’m thinking regex, but it’s been years and years and also I was never a regex wizard.

What kind of Regex replace can I use on the final serialized string to replace any quoted value that starts with function() with the unquoted version of itself? Also, the function itself may have ” in it, in which case the quoted string might have \” in it, which would need to also be replaced back down to “.

I’m assuming I can use a variant of the first answer here:

Finding quoted strings with escaped quotes in C# using a regular expression

but I can’t seem to make it happen. Please help me for the love of god.

I’ve put more sweat into this, and I’ve come up with

    serialized = Regex.Replace(serialized, @"""function\(\)[^""\\]*(?:\\.[^""\\]*)*""", "function()$1");

However, my end result is always:

formatter:function()$1

This tells me I’m matching the proper stuff, but my capture isn’t working right. Now I feel like I’m probably being an idiot with some C# specific regex situation.

Update: Yes, I was being an idiot. I didn’t have a capture around what I really wanted.

   `enter code here` serialized = Regex.Replace(serialized, @"""function\(\)([^""\\]*(?:\\.[^""\\]*)*)""", "function()$1");

that gets my match, but in a case like this:

"formatter":"function() { alert(\"hi!\"); return Highcharts.numberFormat(this.value, 0); }"

it returns:

"formatter":function() { alert(\"hi!\"); return Highcharts.numberFormat(this.value, 0); }

and I need to get those nasty backslashes out of there. Now I think I’m truly stuck.

  • 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-02T04:39:57+00:00Added an answer on June 2, 2026 at 4:39 am
        string serialized = JsonSerializer.Serialize(chartDefinition);
        serialized = Regex.Replace(serialized, @"""function\(\)([^""\\]*(?:\\.[^""\\]*)*)""", "function()$1").Replace("\\\"", "\"");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Highcharts to represent groups of time series. So, data points collected from
I am attempting to use the highcharts javascript library to load charts using this
I'm using HighCharts, and I would like to remove the tooltip from the chart.
I am using highcharts to generate graphical data pulled from a database. I am
I am using HighCharts for a line graph and i am attemping to change
I'm using highcharts to make a piechart but I'm having trouble loading a custom
I've set up some charts using highcharts, populating it's series column using the brilliant
I am using DotNet.Highcharts in conjunction with Visual Studio 2010. I have created an
I'm using highcharts for graphical showcase of statistics. As I understand it,highcharts uses UTC
I am using Highcharts plugin for my web site. So, I have a requirement

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.