[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: a regex

Cameron, Gemma (UK)

10/27/2006 1:32:00 PM


You can split it:

string = 2006%2F10%2Fasdfasdf

year, day, text = string.split(/%2F/)

Should give:
year=2006
day=10
text=asdfasdf

The variables at the beginning are the names you give the different bits
you want out of the string, and you pass the regex or character you want
to split the string with. It's useful for filenames where you can split
on the \.

There is probably a very elegant way of doing this recusively if you
have more than 3 cariables to fish out. ( :

Hope this helps?!

Gem

-----Original Message-----
From: Alexandru Popescu [mailto:the.mindstorm.mailinglist@gmail.com]
Sent: 27 October 2006 14:24
To: ruby-talk ML
Subject: a regex

*** WARNING ***

This mail has originated outside your organization, either from an
external partner or the Global Internet.
Keep this in mind if you answer this message.

Hi!

I have a string in the following form: 2006%2F10%2Fasdfasdf (or more
generic: any_characters+%2Fany_characters+%2Frest_of_it). I am wondering
if I can retrieve the groups 2006, 10, asdfasdf thru a regex (I confess
I couldn't figure it out so far :-( ).

many thanks,

/alex
--
w( the_mindstorm )p.





********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************