Swapnil Sawant Swapnil Sawant - 1 year ago 61
Ruby Question

Regex to remove characters from string upto 3rd last occurance of "/"?


string = "/home/188/tool/public/style_photos/111111117/Detail.jpg"


output = "/style_photos/111111117/Detail.jpg"

what will be the regex to do this.
Please help me.

Answer Source

You can try with below code.

string = string.split('/').last(3).join("/")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download