I ran into this problem when using grep on macOS and found a solution
First of all, I advise you to read this article, which describes the solution to the problem - https://qiita.com/t_o_d/items/fb1f2dd49723b735df2c
For example, if you use the following expression:
(ab|cd|)Then you will get an error "grep: empty (sub)expression"
To prevent this, you need to put $ after cd|:
(ab|cd|$)Also if if you have the same condition at the beginning of the line, for example:
(ab|cd|)some text(ef|gh|)Then in the first condition after cd| you need to put ^, and in the second, as in the previous example - $:
(ab|cd|^)some text(ef|gh|$)Then everything will work without problems on both macOS and Linux
If you want to test your program on macOS, you can use this guide - https://gist.github.com/okineadev/b80d7f9a065543655e203471d582f3f1
I also advise you to use the site https://regex101.com, it is very easy to create regular expressions there
I hope you found this note useful. Have a good day!