Is there any regualar expressions,which Should not allow blank space as the first character for my Department Name field. any helps on this... Thanks -- Posted via http://www.ruby-forum.com/.
Newb Newb wrote:> Is there any regualar expressions,which Should not allow blank space as > the first character for my Department Name field.Yes. Check out the regex documentation in the Pickaxe Book. Pay particular attention to the following constructs: [], \s, and ^ (in both its senses). Or just use String#strip.> any helps on this... > ThanksYou''re welcome! Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
2009/6/18 Newb Newb <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Is there any regualar expressions,which Should not allow blank space as > the first character for my Department Name field. > any helps on this...If you just want to check that the first character of the string is not space (as opposed to stripping off leading whitespace) just check the first character using fieldname[0]. Depending on your requirements it may be more user friendly just to strip off whitespace using strip or strip! Colin
Newb Newb wrote:> Is there any regualar expressions,which Should not allow blank space as > the first character for my Department Name field. > any helps on this... > ThanksIf you''re specifically looking for a regepxp that will match any thing that doesn''t start with a space then try: /^[^\s]/ If it returns nil, there''s a space, if not then there''s no space. Otherwise I''d go with Colin''s approach. Gavin http://handyrailstips.com -- Posted via http://www.ruby-forum.com/.
Gavin Morrice wrote: [...]> If you''re specifically looking for a regepxp that will match any thing > that doesn''t start with a space then try: /^[^\s]/I was trying not to spoon-feed the lazy. :) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Haha Fair enough :) Marnen Laibow-Koser wrote:> Gavin Morrice wrote: > [...] >> If you''re specifically looking for a regepxp that will match any thing >> that doesn''t start with a space then try: /^[^\s]/ > > I was trying not to spoon-feed the lazy. :) > > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org-- Posted via http://www.ruby-forum.com/.