[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

gsub (replace path

pustoi

12/29/2004 4:45:00 PM

Hello,

How can I cut out piece from path in ruby ?
For example I have path like that:

path = /dir/dir/.../dir/content/dir/dir/.../dir/

,where "dir" should be anything

and I need to cut off all before content/dir/dir/.../dir/
Thank you in advance !

1 Answer

Robert Klemme

12/29/2004 4:55:00 PM

0


<pustoi@spils.lv> schrieb im Newsbeitrag
news:1104338672.146157.103190@f14g2000cwb.googlegroups.com...
> Hello,
>
> How can I cut out piece from path in ruby ?
> For example I have path like that:
>
> path = /dir/dir/.../dir/content/dir/dir/.../dir/
>
> ,where "dir" should be anything
>
> and I need to cut off all before content/dir/dir/.../dir/
> Thank you in advance !

17:53:26 [temp]: ruby -e 'p
"/dir/dir/.../dir/content/dir/dir/.../dir/".gsub(%r{^.*(/content)},
"\\1")'
"/content/dir/dir/.../dir/"

Note also:
http://www.ruby-doc.org/core/classes/File.ht...

Regards

robert