Hello, I want a regex to match words that are delimited by double or more space characters, e.g.
ABC DE FGHIJ KLM NO P QRST
Notice double or more spaces between the alphabets. Writing regex for such a problem is easy as I only need the first 4 words, as we may search for a word by using \S+
or \S+?
However, for my problem, only 1 white space CAN occur in a word, for example
AB C DE FG HIJ KLM NO P QRST
Here AB C is a word and FG HIJ is a word as well. In short we want to isolate characters that are spearated by double or more white spaces, I tried using this regex,
.+? +.+? +.+? +.+? +
it matches very swiftly, but it takes too much time for strings it doesn't match. (4 matches are given as an example here, in practice I need to match more).
I am in a need of a better regex to accomplish this, so that all the backtracking can be avoided. [^ ]*
is a regex which will match uptill a space is encountered. Can't we specify a negated character set where we continue matching in case of a single space and break when 2 are encountered? I've tried using positive lookahead but failed miserably.
I would really appreciate your help. Thanks in advance.
Saad