GREP – Removing the trailing forward slash from URLs

Learn / Forums / General InDesign Topics / GREP – Removing the trailing forward slash from URLs

Viewing 2 reply threads
  • Author
    Posts
    • #96367
      Sarah Bunney
      Member

      Hello all,

      I’m trying to solve a bug in my current code to remove the trailing slash from URLs in publications:

      Find: (https://.*|https://.*|www\..*)(/)
      Replace: $1

      This works fine for all standard web URLs (e.g. http://www.google.com/), but not for sub-pages (e.g. http://www.google.com/example/), where it will select the first URL, not the last.

      Help is much appreciated – I’ve been trying all sorts of weird and wonderful things without success!

      Thank you :)

    • #96374

      This is a bit tricky, cause otherwise slashes are removed in the middle, if you start a GREP a second time. Did you realize, that your GREP will find content between two URLs, cause the “*” is greedy?

      Try this one:
      ((https?:|www\.).+)/(?!\w)

      This may not work in every case.

      Kai

      • #96408
        Sarah Bunney
        Member

        Hi Kai,

        Thanks very much for your post! You’re right that I’d been getting the problem of finding everything between two URLs as well, which is unfortunately still the case with your solution (though it’s definitely an improvement on my code!), when a URL is followed by punctuation within a paragraph.

        E.g. Sample sample (www.url.com/) sample sample sample – see http://www.url.com/.

        Thanks again though, it’s a good enough workaround for the documents I’ll be working on, as I can catch the rest manually.

        Sarah

    • #96410

      Sarah, it seems that my previous one wasn’t a good one.

      Try this one:
      Find what: (https?://|www\.)(([^/\s]+/?)+)/
      Change to: $1$2

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
>