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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:20:47+00:00 2026-06-16T04:20:47+00:00

I just need to get all attributes and text from given string via RegExp,

  • 0

I just need to get all attributes and text from given string via RegExp, if it’s possible with one line RegExp would be wonderful. I want to get each attr from string if it is in ” or ‘ or standalone.

  • Attr: value = "1" or value = '1' or value="1" or value='1' or value=1 or value=""
  • Attr: readonly or disabled

I tried, this but not works for me.

var s = '<option value="1" data-foo="Foo" readonly>Value 1</option>', m
m = s.match(/<option ([^>]*)>(.*)<\/option>/)
console.log(m)
// gives ["<option value="1" data-...adonly>Value 1</option>", "value="1" data-foo="Foo" readonly", "Value 1"]

Thanks a lot.

  • 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-16T04:20:48+00:00Added an answer on June 16, 2026 at 4:20 am

    Actually I was needing this for handling “option” elements with a more simple way, more simple regexp. Cos of ie doesn’t not append if use innerHTML = append content for select elements. Append operation is mentioned at links below, but does not work for option elements. And than I find a solution for this problem. If append content is option or options than use handleOptionElements, if not use asyncInnerHTML.

    function append(el, child) {
        if (child.nodeType === 1 || child.nodeType === 3) {
            // Without clone, removes element if it is copied from document
            return el.appendChild(child.cloneNode(true));
        }
    
        content = trim(content);
        if (content.substring(0, 7) === "<option" && 
                content.substring(content.length - 7) === "option>") {
            handleOptionElements(content, el);
        } else {
            el.innerHTML = content;
        }
    
        return el;
    }
    

    http://james.padolsey.com/javascript/asynchronous-innerhtml/
    Ways to increase performance when set big value to innerHTML

    var re_standaloneAttributes = /^(select|disabl)ed$/i,
        re_optionSearch = /<option\s*([^>]*)>(.*?)<\/option>/gi,
        re_attributeSearch = /([^\s]*)=["'](.*?)["']|([\w\-]+)/g;
    
    function handleOptionElements(content, targetElement) {
        var options = [], attributes = [],
             optionElement, optionElements = [], createOption;
    
        (""+ content).replace(re_optionSearch, function(src1, attr, text) {
            if (!src1) return;
            (""+ attr).replace(re_attributeSearch, function(src2, name, value) {
                if (!src2) return;
                name = name || src2;
                value = value || (value = re_standaloneAttributes.test(name) ? name : "");
                attributes.push({name: name, value: value});
            });
            options.push({text: text || "", attributes: attributes});
            // Reset attributes for each element
            attributes = [];
        });
    
        createOption = (function() {
            var option = document.createElement("option");
            return function() { return option.cloneNode(true) };
        })();
    
        forEach(options, function(option) {
            optionElement = createOption();
            // optionElement.text doesn't work on ie 7-8
            optionElement.textContent = optionElement.innerText = option.text;
            forEach(option.attributes, function(attribute) {
                optionElement.setAttribute(attribute.name, attribute.value);
            });
    
            if (targetElement !== undefined) {
                targetElement.appendChild(optionElement);
            } else {
                optionElements.push(optionElement);
            }
        });
    
        return optionElements;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Title pretty much describes it, I just need to get all the order numbers
Is it possible to get all the attributes and methods that a .class file
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I just need to rename JQgrid column dynamically as per user selection from a
I need a pattern that will traverse the document and get me all links
I need to get a list of all Android devices and in order to
I need a way to extract all form information on a webpage, via a
I have a situation where I need to connect multiple DBs to get all
An XSLT-newbie problem: I need to substitute a text value in XML-file. All other
Just need some quick clarification I have 2 Queries in my Access Database that

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.