gsub (replace path)

P

pustoi

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 !
 
R

Robert Klemme

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.html#M000028

Regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top