Use a lazy quantifier:
(\w+?)(sin|in|pak|red)$ ^
Watch the regex demo
\w+ contains a greedy quantifier that: 1) captures as many characters as it can (and note that it can match s , i , all letters, numbers, and underscores), and then backtraces (gives one char after another moving from right to left), trying to adapt to subsequent patterns. Since it is in first, it matches, and the whole group is considered consistent, the regular expression continues to check the end of the line with $ . The left quantifier will have a regex mechanism, skipping \w+? after matching 1, the words char, and other patterns will be checked, moving from left to right.
source share