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

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -