Trim trailing spaces before each new line in a multi-line string
Currently it’s not possible to pass regex modifiers to the |replace filter. You’d have to just do this manually:

{% set str = "foo     \nbar    " %}
{% set trimmed = "" %}

{% for line in str|split("\n") %}
    {% set trimmed = trimmed ~ (trimmed ? "\n") ~ line|replace('/\\s*$/', '') %}
{% endfor %}


UPDATE

As of Craft 2.5, the |replace filter supports regex modifiers.