0

Here I have 3 classes in an element i.e sfCol_20 tsfCol_100 msfCol_100. I want to get the value of the class which is sfCol_{digit} but following logic returns me 3 values. How can resolve this issue?

var matchedClass = $('div').attr('class').match(/sfCol_[0-9]+/g);
console.log(matchedClass);

var re = new RegExp("sfCol_[0-9]+", "g");
if ($('div').attr('class').match(re)) {
  matchedClass = $('div').attr('class').match(re).join(" ");
  console.log(matchedClass);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sfCol_20 tsfCol_100 msfCol_100">
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>
Kiran Shahi
  • 6,738
  • 6
  • 35
  • 66

0 Answers0