I am using R and have the following line below:
s <- "\t\t\t \t\t\thello world ! \t\t\thello"
I want to match the number of spaces at the beginning of the line, and not anywhere else. Therefore, gaps between content should be ignored and only the beginning should be considered. The result will be here "9".
I tried the following, but it only returns the number "1" ...
sapply(regmatches(s, gregexpr('^(\\s)', s)), length)
I am not very good at regular expression, any help is appreciated.
source share