First, you need to figure out the anatomy of the expression that you are given. It describes a string that captures a non-empty sequence of word characters (\\w+)
that begins at a word boundary, which is followed by a non-empty sequence of spaces \\s+
, followed by the content of the captured group, which is not part of a longer word (that is what the \\b
does at the end of the expression).
Next, you need to build a regular expression that describes "a possibly empty sequence of word characters and spaces". That would be (?:\\w|\\s)*
.
Now you are ready to make your expression. You need these parts:
- A capture group that matches a sequence of word characters that begins and ends at a word boundary
- A possibly empty sequence of word characters and spaces that ends at a word boundary
- The value of your captured sequence that ends at a word boundary
- Another possibly empty sequence of word characters and spaces that ends at a word boundary
- The value of your captured sequence that ends at a word boundary