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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:51:51+00:00 2026-05-27T07:51:51+00:00

question: I need to automatically extract all the name properties from this JavaScript (separately

  • 0

question:

I need to automatically extract all the name properties from this JavaScript
(separately for providers large and providers small)

/*
    Simple OpenID Plugin
    http://code.google.com/p/openid-selector/

    This code is licensed under the New BSD License.
*/

var providers_large = {
    google : {
        name : 'Google',
        url : 'https://www.google.com/accounts/o8/id'
    },
    yahoo : {
        name : 'Yahoo',
        url : 'http://me.yahoo.com/'
    },
    aol : {
        name : 'AOL',
        label : 'Enter your AOL screenname.',
        url : 'http://openid.aol.com/{username}'
    },
    myopenid : {
        name : 'MyOpenID',
        label : 'Enter your MyOpenID username.',
        url : 'http://{username}.myopenid.com/'
    },
    openid : {
        name : 'OpenID',
        label : 'Enter your OpenID.',
        url : null
    }
};

var providers_small = {
    livejournal : {
        name : 'LiveJournal',
        label : 'Enter your Livejournal username.',
        url : 'http://{username}.livejournal.com/'
    },
    /* flickr: {
        name: 'Flickr',        
        label: 'Enter your Flickr username.',
        url: 'http://flickr.com/{username}/'
    }, */
    /* technorati: {
        name: 'Technorati',
        label: 'Enter your Technorati username.',
        url: 'http://technorati.com/people/technorati/{username}/'
    }, */
    wordpress : {
        name : 'Wordpress',
        label : 'Enter your WordPress.com username.',
        url : 'http://{username}.wordpress.com/'
    },
    blogger : {
        name : 'Blogger',
        label : 'Your Blogger account',
        url : 'http://{username}.blogspot.com/'
    },
    verisign : {
        name : 'Verisign',
        label : 'Your Verisign username',
        url : 'http://{username}.pip.verisignlabs.com/'
    },
    /* vidoop: {
        name: 'Vidoop',
        label: 'Your Vidoop username',
        url: 'http://{username}.myvidoop.com/'
    }, */
    /* launchpad: {
        name: 'Launchpad',
        label: 'Your Launchpad username',
        url: 'https://launchpad.net/~{username}'
    }, */
    claimid : {
        name : 'ClaimID',
        label : 'Your ClaimID username',
        url : 'http://claimid.com/{username}'
    },
    clickpass : {
        name : 'ClickPass',
        label : 'Enter your ClickPass username',
        url : 'http://clickpass.com/public/{username}'
    },
    google_profile : {
        name : 'Google Profile',
        label : 'Enter your Google Profile username',
        url : 'http://www.google.com/profiles/{username}'
    }
};

openid.locale = 'en';
openid.sprite = 'en'; // reused in german& japan localization
openid.demo_text = 'In client demo mode. Normally would have submitted OpenID:';
openid.signin_text = 'Sign-In';
openid.image_title = 'log in with {provider}';

So I need to:
A) Remove all the C-Style comments
and B) Get all the name values for [providers_large, providers_small] (after the comments have been removed)

So far I have tried regex to remove C-Style comments (and failed)
and regex to get everything between curly braces (and failed)

I subsequently tried to read it in as JSON,
but this of course failed with “invalid json primitve whatever”

This are the stackoverflow-sites I uses
and this are my examples I tried so far

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleExperiments
{

    public class Program
    {

        // http://stackoverflow.com/questions/2538279/strip-out-c-style-multi-line-comments
        // NOT working
        static string RemoveCstyleComments(string strInput)
        {
            string strPattern = @"/[*][\w\d\s]+[*]/";
            //strPattern = @"/\*.*?\*/";
            strPattern = "/\\*.*?\\*/";

            string strOutput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, string.Empty, System.Text.RegularExpressions.RegexOptions.Multiline);
            Console.WriteLine(strOutput);
            return strOutput;
        }


        // http://stackoverflow.com/questions/413071/regex-to-get-string-between-curly-braces-i-want-whats-between-the-curly-brace
        // http://stackoverflow.com/questions/5337166/regular-expression-get-string-between-curly-braces
        // http://stackoverflow.com/questions/1904617/regex-for-removing-curly-brackets-with-nested-curly-brackets
        // http://stackoverflow.com/questions/378415/how-do-i-extract-a-string-of-text-that-lies-between-two-brackets-using-net
        static string GetCurlyValues(string strInput)
        {
            string strPattern = "/{(.*?)}/";
            strPattern = "/{([^}]*)}/";
            strPattern = @"\{(\s*?.*?)*?\}";
            strPattern = @"(?<=\{).*(?=\})";
            strPattern = "{(.*{(.*)}.*)}";
            strPattern = "{{([^}]*)}}";
            strPattern = "{{({?}?[^{}])*}}";
            strPattern = @"\(([^)]*)\)";

            System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(strPattern, System.Text.RegularExpressions.RegexOptions.Multiline);

            System.Text.RegularExpressions.Match mMatch = rex.Match(strInput);

            foreach (System.Text.RegularExpressions.Group g in mMatch.Groups)
            {
                Console.WriteLine("Group: " + g.Value);
                foreach (System.Text.RegularExpressions.Capture c in g.Captures)
                {
                    Console.WriteLine("Capture: " + c.Value);
                }
            }

            return "";
        }


        static void ReadFile()
        {
            try
            {
                string strFilePath = @"TestFile.txt";
                if (System.IO.File.Exists(strFilePath))
                {
                    // Create an instance of StreamReader to read from a file.
                    // The using statement also closes the StreamReader.
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(strFilePath))
                    {
                        string line;
                        // Read and display lines from the file until the end of
                        // the file is reached.
                        while ((line = sr.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        } // Whend

                        sr.Close();
                    } // End Using

                } // End if (System.IO.File.Exists(strFilePath))
                else
                    Console.WriteLine("File \"" + strFilePath + "\" does not exist.");
            } // End Try
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            } // End Catch

        } // End Sub

        public class cProvider
        {
            public string name = "abc";
            public string label ="def";
            public string url ="url";
        }


        public class cProviders_large
        {
            public List<cProvider> foo = new List<cProvider>();
        }


        static void Main(string[] args)
        {
            string strContent = System.IO.File.ReadAllText(@"D:\UserName\Downloads\openid-selector-1.3\openid-selector\js\openid-en - Kopie.js.txt");
            Console.WriteLine(strContent);
            //RemoveCstyleComments(strContent);
            //GetCurlyValues(strContent);
            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            //object obj = js.DeserializeObject(strContent);

            cProviders_large xx = new cProviders_large();
            cProvider ap = new cProvider();
            xx.foo.Add(ap);
            xx.foo.Add(ap);

            string res = js.Serialize(xx);
            Console.WriteLine(res);


            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(" --- Press any key to continue --- ");
            Console.ReadKey();
        } // End Sub Main

    } // End Class Program


} // End namespace ConsoleExperiments

Could anybody who understands regex better than me provide me with the necessary regex-expressions ?
Right now, it looks like I will end-up doing it by hand every time the file changes,
and I really really hate this…

Edit:
On a sidenote, the v8 wrapper uses C++.NET, and thus doesn’t work on Linux, although the v8 engine does work very well on Linux.

So I’m sticking to solving the problem via JSON conversion.

  • 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-27T07:51:52+00:00Added an answer on May 27, 2026 at 7:51 am

    Darin Dimitrov’s answer is certainly the most simple.
    However, Noesis.Javascript is most annoyingly written in C++.NET, which means it cannot be compiled on Linux, although both C#/.NET (via mono) and the v8 engine run excellently on Linux.

    So here is the workout via conversion to JSON and deserialzation:

    static string RemoveCstyleComments(string strInput)
            {
                string strPattern = @"/[*][\w\d\s]+[*]/";
                //strPattern = @"/\*.*?\*/"; // Doesn't work
                //strPattern = "/\\*.*?\\*/"; // Doesn't work
                //strPattern = @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/ "; // Doesn't work
                //strPattern = @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/ "; // Doesn't work
    
                // http://stackoverflow.com/questions/462843/improving-fixing-a-regex-for-c-style-block-comments
                strPattern = @"/\*(?>(?:(?>[^*]+)|\*(?!/))*)\*/";  // Works !
    
                string strOutput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, string.Empty, System.Text.RegularExpressions.RegexOptions.Multiline);
                Console.WriteLine(strOutput);
                return strOutput;
            } // End Function RemoveCstyleComments
    
    
    
    
            static string ReplaceVariables(string strInput)
        {
            string strPattern = @"var\s+providers_large(\s+)?=(\s+)?{(\s+)?";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "\"providers_large\" : {" + Environment.NewLine, System.Text.RegularExpressions.RegexOptions.Multiline);
    
            strPattern = @"(\s+)?var\s+providers_small(\s+)?=(\s+)?{(\s+)?";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, ",   \"providers_small\" : {" + Environment.NewLine, System.Text.RegularExpressions.RegexOptions.Multiline);
    
            strPattern = @"}(\s+)?;(\s+)?";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "}" + Environment.NewLine, System.Text.RegularExpressions.RegexOptions.Multiline);
    
            strPattern = @"$(\s+)?(\w+)(\s+)?:(\s+)?{";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "\"$2\" : {", System.Text.RegularExpressions.RegexOptions.Multiline);
    
            strPattern = @"name(\s+)?:(\s+)?'";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "\"name\" : '", System.Text.RegularExpressions.RegexOptions.Multiline);
    
            strPattern = @"url(\s+)?:(\s+)?'";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "\"url\" : '", System.Text.RegularExpressions.RegexOptions.Multiline);
    
            strPattern = @"label(\s+)?:(\s+)?'";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "\"label\" : '", System.Text.RegularExpressions.RegexOptions.Multiline);
    
    
            strInput = strInput.Replace("'", "\"");
    
    
            strPattern = "openid\\.locale.*";
            //strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "", System.Text.RegularExpressions.RegexOptions.Multiline);
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strPattern, "", System.Text.RegularExpressions.RegexOptions.Singleline);
    
            strPattern = null;
    
            /*
            string[] astrTrailingComments = {
                             @"openid\.locale"
                            ,@"openid\.sprite"
                            ,@"openid\.demo_text"
                            ,@"openid\.signin_text"
                            ,@"openid\.image_title"
            };
    
            foreach (string strThisPattern in astrTrailingComments)
            {
                strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strThisPattern + ".+", "", System.Text.RegularExpressions.RegexOptions.Multiline);
            } // Next strThisPattern
            */
    
            strInput = "{" + strInput + "}";
    
            //Console.WriteLine(strInput);
            return strInput;
        } // End Function ReplaceVariables
    
    
            static System.Collections.Specialized.NameValueCollection TrySerialize(string strInput)
            {
                strInput = RemoveCstyleComments(strInput);
                strInput = ReplaceVariables(strInput);
    
                System.Collections.Specialized.NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection(StringComparer.OrdinalIgnoreCase);
    
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
                dynamic objScript = js.DeserializeObject(strInput);
                js = null;
    
    
                foreach (dynamic kvp in objScript)
                {
                    dynamic dictValues = kvp.Value;
    
                    //Console.WriteLine(Environment.NewLine);
                    //Console.WriteLine(Environment.NewLine);
                    //Console.WriteLine(kvp.Key);
                    //Console.WriteLine(Environment.NewLine);
    
                    foreach (string strMemberVariable in dictValues.Keys)
                    {
    
                        if(StringComparer.OrdinalIgnoreCase.Equals(kvp.Key,"providers_small"))
                        {
                            nvc.Add("providers_small", strMemberVariable);
                        }
    
    
                        if(StringComparer.OrdinalIgnoreCase.Equals(kvp.Key,"providers_large"))
                        {
                            nvc.Add("providers_large", strMemberVariable);
                        }
    
                        //Console.WriteLine(strMemberVariable + ":");
    
                        dynamic MemberVariable = dictValues[strMemberVariable];
                        //Console.WriteLine(MemberVariable.GetType().ToString());
    
                        foreach (string strProperty in MemberVariable.Keys)
                        {
                            //Console.WriteLine(strValue);
                            dynamic objPropertyValue = MemberVariable[strProperty];
    
                            //if (objPropertyValue != null)
                            //Console.WriteLine("     - " + (strProperty + ":").PadRight(8, ' ') + objPropertyValue.ToString());
                        } // Next strProperty
    
                    } // Next strMemberVariable
    
                } // Next kvp
    
    
                // Console.WriteLine("providers large: ");
                // Console.WriteLine(nvc["providers_large"]);
    
                // Console.WriteLine(Environment.NewLine);
                // Console.WriteLine("providers small: ");
                // Console.WriteLine(nvc["providers_small"]);
    
                return nvc;
            } // End Function TrySerialize
    
    
            public static void GetProviders()
            {
                string strContent = System.IO.File.ReadAllText(@"D:\UserName\Downloads\openid-selector-1.3\openid-selector\js\openid-en.js");
                strContent = System.IO.File.ReadAllText(@"D:\UserName\Downloads\openid-selector-1.3\openid-selector\js\openid-ru.js");
                //Console.WriteLine(strContent);
    
                //JavaScriptEngineTest(strContent);
                //GetCurlyValues(strContent);
                System.Collections.Specialized.NameValueCollection nvc = TrySerialize(strContent);
    
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine("providers large: ");
                foreach (string strValue in nvc.GetValues("providers_large"))
                {
                    Console.WriteLine("    " + strValue);
                } // Next strValue
    
                //System.Runtime.Serialization.Json.DataContractJsonSerializer dcjs = new System.Runtime.Serialization.Json.DataContractJsonSerializer();
                // The above is bullshit in unadulterated filth. ==> Use System.Web.Extensions instead
    
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine("providers small: ");
                foreach (string strValue in nvc.GetValues("providers_small"))
                {
                    Console.WriteLine("    " + strValue);
                } // Next strValue
    
            } // End Sub GetProviders
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question but i need it :) $query = SELECT * FROM `set` WHERE
This is a simple and straight forward question.I need to query my database every
Question: I need to call a C# dll from a C++ executable. I use
This is hopefully a softball syntax question: I need to call a method with
For the purpose of the question I need to create a simple fictitious scenario.
For reasons that are irrelevant to this question I'll need to run several SQLite
Question: How to shorten this array creation ? I need to create an array
I need a small FAQ page with Question in bold font and answer in
This question is based on this thread . Do you need the explicit sanitizing
I have a small question. Do i need to declare an array if i

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.