Trying to create a pattern that matches an opening bracket and gets everything between it and the next space it encounters.
I thought \\[.*\\s
would achieve th
I suggest using \[\S*(?=\s)
.
\[
: Match a [
character.\S*
: Match 0 or more non-space characters.(?=\s)
: Match a space character, but don't include it in the pattern. This feature is called a zero-width positive look-ahead assertion and makes sure you pattern only matches if it is followed by a space, so it won't match at the end of line.You might get away with \[\S*\s
if you don't care about groups and want to include the final space, but you would have to clarify exactly which patterns need matching and which should not.