Regex for gsub in rails -
i have rails application using kaminari pagination.
somehow kaminari using wrong url hyperlinks.
right looking easy fix requires regex & gsubbing.
i have url kaminari:
"/bookings/hotels//pune?arrival_date=....."
i want replace part - /hotels//pune?
- /hotels?
there other string in place of pune
(it might change).
how should ?
capture , replace using match capture
gsub(/hotels(\/\/\w+)\?/){|m| m.gsub($1, '')} str = "/bookings/hotels//pune?arrival_date=....." str.gsub(/hotels(\/\/\w+)\?/){|m| m.gsub($1, '')} #=> "/bookings/hotels?arrival_date=....."
Comments
Post a Comment