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

Joan Crawford - “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

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 - “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

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 - “Sports is like a war without the killing.”

Thanks buddies !

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