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?
You can make your regex much simpler like:
Edit: If you need to account for no quotes at all try this one: