Template - string to integer

I’m trying to split out (strip?) and convert scraped network data (bits), presented as a string, into an integer.

  - platform: scrape
    resource: http://<redacted>
    name: data out
    select: 'p:nth-of-type(3)'

Before the value template is applied I receive this string:
In: 8,186,964,137↵Out: 154,453,055↵Total: 8,341,417,192↵

After applying the template
value_template: {{states.sensor.jwandata.state.split(’:’ or ‘\n’ or ’ ')[1] |replace(“Out”, “”) }}
and I worked at that for a while :slight_smile: ) I am closer to just having the 8,186,964,137 string but I sense there is a better way to extract the number and turn it into an integer. I’ve tried to add |int but it does not work in the template testing page in HA. I also wonder if white spaces are hidden in there?

Thoughts? Appreciate any suggestions.

This should return the number after “Out”:
{{ states.sensor.jwandata.state.split()[3] | replace(",", "") | int }}

split() splits the string on whitespace resulting in
['In:', '8,186,964,137', 'Out:', '154,453,055', 'Total:', '8,341,417,192']
Select the third element with [3], replace the thousands separator "," with "" and convert to int.

That worked - thank you e02jr! Appreciate it.