Extract common repeating substrings out of alternation

Consider the following pattern:

(playground|player|playing) 

Instead of using the preceding pattern, it is better to extract the common substring, play, and move it to the left of alternation, as follows:

play(ground|er|ing) 

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.