Regex to target last two spaces in a string

Regex newbie here. I’m trying to write an expression that matches the last two (or n) separate spaces.

       v v
This is a test

I have an ultra simple expression that returns the last space:
/ (?=[^ ]*$)/i
but cannot seem to figure out how to get it to return twice and only twice (or n times)

1 thought on “Regex to target last two spaces in a string”

Leave a Comment