Regular Expression:
/@([\S]*?(?=\s)(?!\. ))/g
Given String:
'this string has @var.thing.me two strings to be @var. replaced'.replace(/@([\S]*?(?=\s)(?!\. ))/g,function(){return '7';})
Expected Result:
'this string has 7 two strings to be 7. replaced'
If you'd like to improve it, I am attempting to match Razor Html Encoded Expressions, but please note the condition of not matching an ending period followed by a space. The example above demonstrates this with the first capturing as @var.thing.me
and the second (shorter) one as just @var
.