Jul 14, 2021 at 7:05am
Change pos2 to pos2-pos in the substring argument. The substr() method works by number of characters, not by slicing as in many other languages.
But I think you need to consider carefully what happens if one of those target strings is not found.