Hello I am very week with regular expressions. It may be too easy for someone. I have following regular expression loc_content_re = /(?:([A-Za-z\s:]*?):)?([\s\S]*)/> content = "HYDERABAD/NEW DELHI: Andhra Pradesh chief minister was ...." >I wanted to extract "HYDERABAD/NEW DELHI" from above content match_re = loc_content_re.match(content)> location = $1 > plain_content = $2 >It shows location nil and plain_content as passed One more, What will be the regular expression to extract IANS and 3 September 2009, 02:57pm IST from following " IANS 3 September 2009, 02:57pm IST " Thanks ! Sandip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well for the example string you have given, this does the job : reg = /(.*):\s+(.*)/ s = "HYDERABAD/NEW DELHI: Andhra Pradesh chief minister was ...." reg.match(s) location = $1 # = "HYDERABAD/NEW DELHI" plain_content = $2 # = "Andhra Pradesh chief minister was ...." Thanks & Regards, Dhruva Sagar. Joan Crawford<http://www.brainyquote.com/quotes/authors/j/joan_crawford.html> - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend." On Fri, Sep 11, 2009 at 2:06 PM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello > > I am very week with regular expressions. It may be too easy for someone. > > I have following regular expression > > loc_content_re = /(?:([A-Za-z\s:]*?):)?([\s\S]*)/ >> content = "HYDERABAD/NEW DELHI: Andhra Pradesh chief minister was ...." >> > > > I wanted to extract "HYDERABAD/NEW DELHI" from above content > > match_re = loc_content_re.match(content) >> location = $1 >> plain_content = $2 >> > > > It shows location nil and plain_content as passed > > > One more, > > What will be the regular expression to extract > IANS and > 3 September 2009, 02:57pm IST > from following > " IANS 3 September 2009, 02:57pm IST " > > Thanks ! > Sandip > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks ! What will be the regular expression to extract *IANS* and *3 September 2009, 02:57pm IST* from following string *" IANS 3 September 2009, 02:57pm IST "* Sandip -- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.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 -~----------~----~----~----~------~----~------~--~---
reg = /(.*)\s([0-9]\s.*)/ s = " IANS 3 September 2009, 02:57pm IST " reg.match(s) location = $1.strip # = "IANS" plain_content = $2.strip # = "3 September 2009, 02:57pm IST" Thanks & Regards, Dhruva Sagar. Ogden Nash <http://www.brainyquote.com/quotes/authors/o/ogden_nash.html> - "The trouble with a kitten is that when it grows up, it''s always a cat." On Fri, Sep 11, 2009 at 4:28 PM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks ! > > > What will be the regular expression to extract > *IANS* and *3 September 2009, 02:57pm IST* > from following string > > *" IANS 3 September 2009, 02:57pm IST "* > > > Sandip > -- > Ruby on Rails Developer > http://sandip.sosblog.com > http://funonrails.wordpress.com > www.joshsoftware.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 -~----------~----~----~----~------~----~------~--~---
Hi If i have an file name bangalore.txt if i wanna remove .txt and assign bangalore to temp variable how can it achieve. Regards prashanth On Fri, Sep 11, 2009 at 5:13 PM, Dhruva Sagar <dhruva.sagar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> reg = /(.*)\s([0-9]\s.*)/ > s = " IANS 3 September 2009, 02:57pm IST " > reg.match(s) > location = $1.strip # = "IANS" > plain_content = $2.strip # = "3 September 2009, 02:57pm IST" > Thanks & Regards, > Dhruva Sagar. > > > Ogden Nash <http://www.brainyquote.com/quotes/authors/o/ogden_nash.html> - "The trouble with a kitten is that when it grows up, it''s always a cat." > > On Fri, Sep 11, 2009 at 4:28 PM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Thanks ! >> >> >> What will be the regular expression to extract >> *IANS* and *3 September 2009, 02:57pm IST* >> from following string >> >> *" IANS 3 September 2009, 02:57pm IST "* >> >> >> Sandip >> -- >> Ruby on Rails Developer >> http://sandip.sosblog.com >> http://funonrails.wordpress.com >> www.joshsoftware.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 -~----------~----~----~----~------~----~------~--~---
1. Go to Google.com 2. Type keywords: Ruby File basename 3. Press "I am feeling lucky" Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Fri, Sep 11, 2009 at 5:37 PM, prashanth hiremath < prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi > > If i have an file name bangalore.txt > if i wanna remove .txt and assign bangalore to temp variable how > can it achieve. > > Regards > prashanth > > > > > On Fri, Sep 11, 2009 at 5:13 PM, Dhruva Sagar <dhruva.sagar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> reg = /(.*)\s([0-9]\s.*)/ >> s = " IANS 3 September 2009, 02:57pm IST " >> reg.match(s) >> location = $1.strip # = "IANS" >> plain_content = $2.strip # = "3 September 2009, 02:57pm IST" >> Thanks & Regards, >> Dhruva Sagar. >> >> >> Ogden Nash <http://www.brainyquote.com/quotes/authors/o/ogden_nash.html> - "The trouble with a kitten is that when it grows up, it''s always a cat." >> >> On Fri, Sep 11, 2009 at 4:28 PM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >> >>> Thanks ! >>> >>> >>> What will be the regular expression to extract >>> *IANS* and *3 September 2009, 02:57pm IST* >>> from following string >>> >>> *" IANS 3 September 2009, 02:57pm IST "* >>> >>> >>> Sandip >>> -- >>> Ruby on Rails Developer >>> http://sandip.sosblog.com >>> http://funonrails.wordpress.com >>> www.joshsoftware.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you need RegExp help this would help you : s = ''Bangalore.txt'' regexp = /(.*)\.(/*)/ regexp.match(s) baseName = $1 # = "Bangalore" But I must say, you should try google a bit more often as Abhinav mentioned. Thanks & Regards, Dhruva Sagar. Ted Turner <http://www.brainyquote.com/quotes/authors/t/ted_turner.html> - "Sports is like a war without the killing." On Fri, Sep 11, 2009 at 5:37 PM, prashanth hiremath < prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi > > If i have an file name bangalore.txt > if i wanna remove .txt and assign bangalore to temp variable how > can it achieve. > > Regards > prashanth > > > > > On Fri, Sep 11, 2009 at 5:13 PM, Dhruva Sagar <dhruva.sagar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> reg = /(.*)\s([0-9]\s.*)/ >> s = " IANS 3 September 2009, 02:57pm IST " >> reg.match(s) >> location = $1.strip # = "IANS" >> plain_content = $2.strip # = "3 September 2009, 02:57pm IST" >> Thanks & Regards, >> Dhruva Sagar. >> >> >> Ogden Nash <http://www.brainyquote.com/quotes/authors/o/ogden_nash.html> - "The trouble with a kitten is that when it grows up, it''s always a cat." >> >> On Fri, Sep 11, 2009 at 4:28 PM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >> >>> Thanks ! >>> >>> >>> What will be the regular expression to extract >>> *IANS* and *3 September 2009, 02:57pm IST* >>> from following string >>> >>> *" IANS 3 September 2009, 02:57pm IST "* >>> >>> >>> Sandip >>> -- >>> Ruby on Rails Developer >>> http://sandip.sosblog.com >>> http://funonrails.wordpress.com >>> www.joshsoftware.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 -~----------~----~----~----~------~----~------~--~---