How can I match only two words that are separated by one or more spaces?
[\w]+[\s]+[\w]+
matches:
one two
one two three //but this should not match as it countains more than 2 words
How can I match only two words that are separated by one or more spaces?
[\w]+[\s]+[\w]+
matches:
one two
one two three //but this should not match as it countains more than 2 words
You can use this regex with line start and end anchors :
^\\s*\\w+\\s+\\w+\\s*$
Note use of ^
and $
that makes sure only two word string
, separated by space is matched.