I would like to remove a wildcard string of text from an existing string, then append it to after a div.
In my case, I'd like to find a part number from within a string, and then set that string to a variable.
So instead of this (please note between [] can be anything):
<div> The part number is [8F8S0JJ9]</div>
<div> The second part number is [V9S7D73]</div>
I would have:
<div> The part number is</div>
[8F8S0JJ9]
<div> The second part number is</div>
[V9S7D73]
Here's my code:
// Get the product number that lies between [ ] marks from all div elements
$('div:contains('['+*+']')').html(function() {
//Look for the wildcard string and save it to a variable. how can I search within the string?!
var $finalstring = $(this).search('['+*+']');
//remove it from the string
$(this).replace($finalstring, '');
//Set it to display after the string
$(this).append($finalstring);
});
Thanks