Extract a numeric value out of o string

Hi,

I want to export the numeric part out of a string from a rest sensor.

{{ states.sensor.pv_rest.state }}

The string is eg.:

1879xyz

The result should be just the number 1879.
The problem is the the number can also be eg. 99-> just two letters… or 123456->6 letters…

How do I get the numeric value? I think about something like substring, length, find??

Thanks for your help.

I’m not sure if this helps with your case.

{% set s= '1879xyz' %}
{% for i in s|list if i == i|int|string%}
{{- i -}}
{% endfor %}

Thank you!