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)

69 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
  2. 455573 130972Hey there, I believe your blog may possibly be having browser compatibility issues. When I look at your site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, superb blog! 493659

    Reply

Leave a Comment