Based on the fact that you are calling encodeURIComponent method I'm assuming that apiSource is not encoded, wouldn't it be better than to just use not encoded regex?