san2821
September 11, 2009, 10:37am
1
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
san2821
September 11, 2009, 10:47am
2
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.”
san2821
September 11, 2009, 1:00pm
3
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
Auf SOSblog geht es um aktuelle Blogs, Neuigkeiten, Artikel, Webseiten und Medien. Wir bringen interessante neue Webseiten aus den Tiefen des Webs.
JoshSoftware offers custom software development Services & Solution that provides enterprise, software development services for web & mobile.
Est. reading time: 51 minutes
san2821
September 11, 2009, 1:45pm
4
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…
“The trouble with a kitten is that when it grows up, it’s always a cat.”
san2821
September 11, 2009, 2:17pm
5
Go to Google.com
Type keywords: Ruby File basename
Press “I am feeling lucky”
Thanks,
Abhinav
–
अà¤à¤¿à¤¨à¤µ
http://twitter.com/abhinav
On Fri, Sep 11, 2009 at 5:37 PM, prashanth hiremath <
san2821
September 11, 2009, 2:29pm
6
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…
“Sports is like a war without the killing.”
On Fri, Sep 11, 2009 at 5:37 PM, prashanth hiremath <
san2821
September 14, 2009, 4:07pm
7
Thanks buddies !
I am sure that in next couple of hours, will able to write complex
regex !
–
Sandip
san2821
September 11, 2009, 2:09pm
8
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