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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:18:06+00:00 2026-06-12T08:18:06+00:00

The end aim … to retrieve a group of DIVs with specific attributes/values and

  • 0

The end aim… to retrieve a group of DIVs with specific attributes/values and update the element type and manipulate the attribute and value…

I’d like to use RegEx to test the following scenario (I believe is correct based on the above aim)

  • for each opening DIV
  • that contains an attribute-to-check attribute
    • The attribute may or may not be the first attribute
  • that has a value containing value-contains
    • The value may or may not be the first value in the attribute (allowing for future extensions)
  • find its closing DIV
    • This DIV itself may contain other DIVs – including other DIVs that will also be matched

So what have I tried? …Using the test script:

<p>test1</p>
<DIV attribute-to-check='notvalid'>
  test2
</DIV>
<p>test3</p>
<DIV attribute-to-check='value-contains:2012-12-12' class='test4'>
  test5
</DIV>
<p>test6</p>
<DIV attribute-to-check='value-contains:2012-01-01' class='asd'>
  test6
</DIV>
<p>test7</p>

I’ve got as far as the following RegEx…

<?DIV.*?attribute-to-check='value-contains:.*?>(.*?)</DIV>

BUT this brings back

string 1: "<DIV attribute-to-check='notvalid'>test2</DIV>test3<DIV attribute-to-check='value-contains:2012-12-12' class='test4'>test5</DIV>"

string 2: "<DIV attribute-to-check='value-contains:2012-01-01' class='asd'>test6</DIV>"

I suspect it’s bringing back test2 in string1 as this has an opening div with the attribute-to-check but the value is notvalid? so I’m wondering if I’m getting the first DIV then any number of characters until it locates any other attribute-to-check='value-contains: and then the closing DIV after that?

I am struggling to navigate from this point and would appreciate any helpers from the community 🙂

Thanks
Dylan

  • 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-12T08:18:07+00:00Added an answer on June 12, 2026 at 8:18 am

    Please, Don’t use regex for HTML. No, seriously, don’t.

    JQuery has awesome selector syntax to do just what you want, really. Look here, where it shows you how to do what you want way at the top of the documentation.

    For example:

    $('div[attribute-to-check|="value-contains:"]')
    

    Will yield divs with your required attribute/value constraint.

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

Sidebar

Related Questions

Aim: my UINavigationBar has to be customized with a certain background and a specific
Aim To Achieve : I want to add the prevMonth's name at the end
My aim is to retrieve CLOB data from the database into a textarea in
End of line anchor $ match even there is extra trailing \n in matched
The end goal of this part of my project is to be able to
My end goal is local development of a Radiant CMS installation. So, need rails
Error: End tag for 'optgroup' which is not finished. You have probably failed to
I end up typing grep -Rni pattern . and awful lot. How do I
Back-end: I have a model (User) that has_many of another model (ContactPreference). Front-end: An
My end objective is to create an applescript that intelligently inserts a bullet point

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.