lastIndexOf to find 3 consecutive space
I want to find 3 consecutive space in a string.
SO far i've triedstr.indexOf(" ")
str.match(/\s\s\s+/)
none of them worked [both returns 1, and detect single space as 3 space]
Edit
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:
str.search(/ {3}/)
It'll return the index of the first three consecutive spaces (or -1
if there's no match).
If you want to match three or more spaces, you can use this repetition syntax:
str.search(/ {3,}/)
精彩评论