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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:08:39+00:00 2026-06-12T16:08:39+00:00

Ok, I admit it, I suck at Regular Expressions. I’m trying to get the

  • 0

Ok, I admit it, I suck at Regular Expressions. I’m trying to get the value of attribute data-hover-id.

I have the following javascript code:

var editText = "<span class='hover-content' data-hover-id='2' >Some text</span>";

var hoverId = -1;

// Get HoverID if it exists
var regex = /span.*data-hover-id=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/;
var result = regex.exec(editText);
if (result.length > 1) {
  hoverId = result[1];
}

The results of the above code is hoverId equals ‘2 (apostrophe 2).

I want the value 2 without the quote or apostrophe. What would the regular expression be in this case? Is there a better way to do this in Javascript?

  • 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-12T16:08:41+00:00Added an answer on June 12, 2026 at 4:08 pm

    You can make your regex much simpler like:

    var re = /data-hover-id=["'](.+)["']/;
    var result = re.exec(str)[1];
    

    Edit: If you need to account for no quotes at all try this one:

    /data-hover-id=['"]?([^\s>]+)['"]?/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll admit I'm rubbish at regular expressions and find some of the tools out
I admit, I'm noob when it comes to sourceforge. I'm trying to get the
I have to admit that having not even tried to code this myself this
I admit that I have almost none experience of unittesting. I did a try
I'll admit, I am pretty new with ASP .NET programming and I have been
I need to suck data from stdin and create a object. The incoming data
I admit, after all these years I suck at regex. I am hoping someone
I must admit that I have extreme diffculties in using the pysvn module. Unlike
I will admit, I don't know much about PHP and have google'd around for
I have to admit, I was quite shocked to see how many lines of

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.