Can Anyone help me with regular expression which checks the string, if it contains Leading whitespaces. example => admin it contains leading space with it. so i need to check it. pls help me. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Can Anyone help me with regular expression which checks the string, if > it contains Leading whitespaces. > example > => admin > it contains leading space with it. > so i need to check it. > pls help me.Read up on the Regex class and pattern matching in general... str = " some string with a leading space" if str =~ /^\s/ puts "we have a leading space" else " puts "we don''t" end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> Can Anyone help me with regular expression which checks the string, if >> it contains Leading whitespaces. >> example >> => admin >> it contains leading space with it. >> so i need to check it. >> pls help me. >> > > Read up on the Regex class and pattern matching in general... > > str = " some string with a leading space" > > if str =~ /^\s/ > puts "we have a leading space" > else " > puts "we don''t" > end >Not directly related, but if you just need to remove the leading/ trailing spaces, you could use lstrip, rstrip and strip on strings. Cheers, Mohit. 2/7/2009 | 2:25 PM. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---