what does the .\s* means in the following commad
class String
def sentences
gsub(/\n|\r/, ’ ').split(/.\s*/)
end
end
what does the .\s* means in the following commad
class String
def sentences
gsub(/\n|\r/, ’ ').split(/.\s*/)
end
end
\s* means occurrence of zero or more white spaces.
gsub(/\n|\r/, ’ ').split(/.\s*/) is basically first removing all the
line feeds and carriage returns and then the sentence is split into an
array whenever a dot followed by zero or more white spaces is
encounterd.
Regards,
Raghav
griffith Khana wrote:
what does the .\s* means in the following commad
it’s actually ‘.\s*’ => match a ‘.’ followed by zero or more spaces
read the regular-expression section for more details:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html
class String
def sentences
gsub(/\n|\r/, ’ ').split(/.\s*/)
end
end
–
Kind Regards,
Rajinder Y.
Do Good! - Share Freely
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs