2017-11-11 131 views

回答

3

\s++(?=[^[]*])

\s++ 
matches any whitespace character (equal to [\r\n\t\f\v ]) 
++ Quantifier — Matches between one and unlimited times, as many times as possible, without giving back (possessive) 
Positive Lookahead (?=[^[]*]) 
Assert that the Regex below matches 
Match a single character not present in the list below [^[]* 
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
[ matches the character [ literally (case sensitive) 
] matches the character ] literally (case sensitive) 

(?:\[|\G(?!^))[^]\s]*\K\s+

Non-capturing group (?:\[|\G(?!^)) 
1st Alternative \[ 
\[ matches the character [ literally (case sensitive) 
2nd Alternative \G(?!^) 
\G asserts position at the end of the previous match or the start of the string for the first match 
Negative Lookahead (?!^) 
Assert that the Regex below does not match 
^ asserts position at start of the string 
Match a single character not present in the list below [^]\s]* 
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
] matches the character ] literally (case sensitive) 
\s matches any whitespace character (equal to [\r\n\t\f\v ]) 
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match 
\s+ 
matches any whitespace character (equal to [\r\n\t\f\v ]) 
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)