Replace (to change links)

  • has just changed their links.

    For instance, I would change all the links:
    <a href=“”>
    <a href=“”>
    textvariable is a variable
    the changes concern:

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

    Is there a solution?
    Thanks very much!

  • @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="">
    <a href="">
    <a href="https://dontchange.example.url/somethingelse">
    <a href="">

    desired data:

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

    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.

  • @PeterJones said in Replace (to change links):

    FIND = href=“[^"]*)
    REPLACE = href=“${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.

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

Log in to reply