How do i replace multiple instances of %20 in a filename ?

Posted on 2008-11-07
Last Modified: 2012-05-05

At present i'm using the following Javascript to replace %20 with  " " (a blank space):

hs.captionEval = 'this.content.src.substring(this.content.src.lastIndexOf("/")).replace("/", "").replace(".jpg", "").replace("%20", " ")';

It works but it only replaces the first %20 rather than all of them, so that a long image filename now reads:
Hello to%20you%20my%20dear%20sir

How do i fix this?

Many thanks
click on the England pushpin marker > Norwich arrow marker > home icon
Question by:Daniish
    LVL 82

    Accepted Solution

    hs.captionEval = 'this.content.src.substring(this.content.src.lastIndexOf("/")).replace("/", "").replace(".jpg", "").replace(/%20/g, " ")';
    LVL 21

    Expert Comment

    use global reg expression that goes to end of line $ <--using end of line character and /g for globally change all over page...
    LVL 21

    Expert Comment

    LVL 82

    Expert Comment

    glad to help

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now