Regular expression help needed

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

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 S…

Joan
Crawfordhttp://www.brainyquote.com/quotes/authors/j/joan_crawford.html

  • “I, Joan Crawford, I believe in the dollar. Everything I earn, I
    spend.”

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

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 S…

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.”

  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 <

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 S…

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 <

Thanks buddies !

I am sure that in next couple of hours, will able to write complex
regex !


Sandip

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs