1

I have an HTML string which contains, among CSS and HTML markup, some tags with CSS classes. How do I get the collection of classes? I'd like to do:

htmlString.replace(patternForEveryClass, "somePrefix_"+capturedGroupIndex);

where the pattern must collect all classes into a tag, and capturedGroupIndex must be the index of the captured class.

This is the regex I have right now:

class="((\s|[a-zA-Z_-]{1}[\w-_]+)+)"

https://regex101.com/r/pI9nX2/2

Is there a way to collect all instances within the class="" attribute? I cannot use DOM JS, just string scrapping.

TylerH
  • 20,816
  • 57
  • 73
  • 92
alexserver
  • 1,288
  • 2
  • 15
  • 30

0 Answers0