Please be noted that expression try to choice the pattern of maximum length (gready regex) match. As you see in your example (regex: symbols between parenthesis) have choiced
- ...is ( test.com) and (alex )
instead of
- ...is (test.com) and (alex).
There are two ways to override such behavior:
- Substitute
any symbolbyrevers matchof limit or devide symbol (for example:(.*)by([^)]*) - Modern regular expressions (PCRE for example) allow a quantifier to be specified as lazy. They put a question mark after the quantifier to make it lazy
.*?. By using a lazy quantifier, the expression tries the minimal match first.
More over the first variant allows to some simplify regex: grep -Po '\(\K[^)]*'