Tuesday, October 5, 2010

Finding all class declarations in an HTML document

I was charged with the ever so tedious task of removing all class declarations from XHTML documents. In order to find them it took me a while to find the proper general expression. I'm not regexp-litterate. Here's the explained result:

 (class|styleClass)=\"[^\"]+\"

It means find a string with the following properties:

  • Starts with a space character (granted, this may not catch all cases, but you can tweak it).
  • Then look for "class" or "styleClass", which is a way to declare it in JSF
  • Now an "=" and double quotes
  • Followed by anything except double quotes (this keeps it from including the subsequent attributes in the find)
  • Ends in double quotes

No comments:

Post a Comment