How do clean_class and clean_id work? I am new to Drupal 8 and Twig syntax. I am not able to understand how the clean_class filter works in region|clean_class. What is clean_class? I have added the following code in the page.html.twig file.
{%
  set classes = [
    'region',
    'region-' ~ region|clean_class,
  ]
%}
    
{{ dump(classes) }}

It prints this.
array (size=2)
  0 =&gt; string 'region' (length=6)
  1 =&gt; string 'region-' (length=7)
clean_class is a filter which invokes the \Drupal\Component\Utility\Html::getClass() method on the string, which:


  Prepares a string for use as a valid class name.


Basically it removes invalid characters from HTML classes in preparation for rendering. clean_id is the equivalent for HTML IDs.

There are other filters registered by core too, see TwigExtension::getFilters for more details.