# [JavaScript (SpiderMonkey)], 82 bytes <!-- language-all: lang-javascript --> s=s.replace(/(\S+ +(\S+))\(s\)\B/g,(_,a)=>a+("s"[+/^(1|one|an?)\b/i.test(a)]||"")) [Try it online!][TIO-j8aibrfe] [JavaScript (SpiderMonkey)]: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/45 [TIO-j8aibrfe]: https://tio.run/##XVHBbsMgDL3nKywuA6VL1nOWTdpt5x2bbnITL2GjgIC0mpR/zyCNtK5GgP14fgbzhSf0rZM23HsrO3JHo7/pZy5LwK6jDpgjq7ClmntRPzH4NA5GT3AgZc7ApY6ICeREdkIHVo0O1YU7@9oXazYvefOWQ55WIRruG9G8lP2Gf2wwUjHnzLNdXr7z7WQ0TaifRXMoZRHIB45iP02MCTFXqYjUdgxQZ6zJwkCOAOMMZwMH1HHE4oC6g6gDiqyjdsBRR7TRa8KdB7whh8FRFLJW0cq89pPUdbz9y07hJUherObJnQiiGSd7qVHBYudBxrfY1ItV40YE9b8SYZAeZLpoSFBI2CvgMQIpdKh7ciuXFd4qGThrNBNVlsU/4kujoIaHDai4LT0rFOk@DFU8eAQVtzwXGUBrtDeKCmV6fvlAvtB3ci9ENf8C "JavaScript (SpiderMonkey) – Try It Online" ### 78 Byte version (less robust) `s=s.replace(/(\S+ +(\S*))\(s\)/g,(_,a)=>a+("s"[+/^(1|one|an?)/i.test(a)]||""))` This is a modified version of ETHproductions' (I don't have 50 rep.) ### Explanation - `/(\S+ +(\S+))\(s\)/g` - the actual pattern to look for (`amount object(s)`) - `(_,a)=>a` - `_` is a catch all variable, `a` is the `(\S+ +(\S+))` - `"s"[+/^(1|one|an?)/i.test(a)]||""` - instead of slicing the array, just make a dummy array and get the index (`+/.../.test` returns a number) - should `"s"[+/^(1|one|an?)/i.test(a)]` return `undefined` (`true`, or `1` for the test) return `""`