• Login
Community
  • Login

Replace (to change links)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 277 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X
    Xen le Cam
    last edited by Mar 3, 2021, 5:05 PM

    Archive.org has just changed their links.

    For instance, I would change all the links:
    <a href=“https://archive.org/stream/textvariable ”>
    to:
    <a href=“https://archive.org/details/textvariable?view=theater ”>
    textvariable is a variable
    the changes concern:

    1. stream > details
    2. and add ?view=theater betwen / and "

    Is there a solution?
    Thanks very much!

    P 1 Reply Last reply Mar 3, 2021, 5:19 PM Reply Quote 0
    • P
      PeterJones @Xen le Cam
      last edited by Mar 3, 2021, 5:19 PM

      @Xavier-Negre ,

      Is there a solution?

      very likely, yes.

      It would help if you gave us better example data than a single instance, however.

      My best guess as to what you want:
      original data:

      <a href="https://archive.org/stream/textvariable">
      <a href="https://archive.org/stream/othertext">
      <a href="https://dontchange.example.url/somethingelse">
      <a href="https://archive.org/stream/somethingelse">
      

      desired data:

      <a href="https://archive.org/details/textvariable?view=theater">
      <a href="https://archive.org/details/othertext?view=theater">
      <a href="https://dontchange.example.url/somethingelse">
      <a href="https://archive.org/details/somethingelse?view=theater">
      
      • FIND = href="https://archive.org/stream/([^"]*)"
      • REPLACE = href="https://archive.org/details/${1}?view=theater"
      • SEARCH MODE = regular expression
      • REPLACE ALL

      If this isn’t the right behavior, you need to describe your problem better. Follow the advice below.
      ----

      Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

      P 1 Reply Last reply Mar 3, 2021, 5:21 PM Reply Quote 1
      • P
        PeterJones @PeterJones
        last edited by Mar 3, 2021, 5:21 PM

        @PeterJones said in Replace (to change links):

        FIND = href=“https://archive.org/stream/([^"]*) ”
        REPLACE = href=“https://archive.org/details/${1}?view=theater ”

        I forgot a quick explanation: most of that is simple text in the search and replace.

        • SEARCH: The [^"]* says "search for 0 or more characters that aren’t a quote-mark. The () wrapping that section says “save that text (which you called textvariable) into capture group #1”. The quote at the end is literal text again.
        • REPLACE: most is literal text. the ${1} says to take the contents of group#1 and use that in the replacement string.
        1 Reply Last reply Reply Quote 2
        • X
          Xen le Cam
          last edited by Mar 3, 2021, 10:29 PM

          It works! It’s fantastic… and magic!
          Thanks very much indeed, for the solution and the comment: very good!

          1 Reply Last reply Reply Quote 1
          1 out of 4
          • First post
            1/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors