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)

56 thoughts on “Regex to target last two spaces in a string”

  1. hello!,I like your writing very a lot! proportion we communicate extra approximately your article on AOL? I need an expert on this space to resolve my problem. Maybe that’s you! Having a look forward to peer you. |

    Reply

Leave a Comment