I have an URL like this:
http://site.com/galleries/galleryname/imageID123/lightbox/
and using a script to replace the lightbox URL with nothing (when lightbox overlay is closed):
document.URL.replace('lightbox/', '')
Things get messy when user has a gallery also named “lightbox”, then the URL is:
http://site.com/galleries/lightbox/imageID123/lightbox/
I need to make sure that docment.URL.replace will replace only the last occurrence of the word.
try this
Im talking as the parser :
Ok , whenever i find
lightbox/i will replace it with"empty"but wait ! there’s more than 1 . so I’ll do it .
but wait ! since you didnt supply the
gflag – i will do it only to the first.(if you did supply the g flag it will replace ALL occurrences !)
any way –
we dont want that.
so how do we tell him only the last ?
well use the
$sign. which represent the end of the string.so i want you to replace only lightbox which has
/after and the/is the END OF THE WORD.