I want to find 3 consecutive space in a string.
SO far i’ve tried
str.indexOf(" ")
str.match(/\s\s\s+/)
none of them worked [both returns 1, and detect single space as 3 space]
Edit
Sample Input:
Blah blah 1space 2space 3space lots of spaceNo space
It breaks^ here and detect it as 3 space [FF 4]
Your regex looks close, except you’re searching for
\s(which also matches tabs and newlines), and you’re searching for 3+ (not exactly 3). Try using this instead:It’ll return the index of the first three consecutive spaces (or
-1if there’s no match).If you want to match three or more spaces, you can use this repetition syntax: