问题
Given a string,
mystr = "Average student score 88"
I wish to split if there are more than 1 space. I wish to obtain the following:
"Average student score" "88"
I searched that "\s+" will split by any number of spaces.
strsplit(mystr, "\\s+")
But this is not what I want. Is there any option within strsplit that can split strings based on a certain number of spaces (say space = k) or a rule on spaces (say space > 1)?
回答1:
You may specify it through a repetition quantifier.
strsplit(mystr, "\\s{2,}")
\\s{2,}
regex should match two or more spaces.
来源:https://stackoverflow.com/questions/34916149/strsplit-by-spaces-greater-than-one-in-r