Find in files, Replace!



  • I have an immense website and the 'find in files, replace ’ has been a lifesaver…literally.

    But now I want to remove a complete (specific) column from all of the pages. I have tried to do it like this and variances thereof with no avail…

    find what:
    <td><p class=“d”>…<td><p class=“b”>

    replace with:
    <td><p class=“b”>*

    …hoping I can wipe out every cell of this column from every page in a swipe, but I have yet to find the answer. There is an ‘extended’ option that looks like the answer, but I have not unlocked the door to this as of yet…

    Can anyone advise on this?



  • @Kirk-Lauritzen

    what exactly do you think your find what and replace with is doing?



  • @Kirk-Lauritzen ,

    The official docs on “Searching” describe the three modes of search/replace. TL;DR =

    1. regular search = every character in the FIND and REPLACE boxes are literal, so no wildcards or fancy stuff
    2. extended mode = most characters are literal, but the sequences listed in the dialog box (and a few others), do something special, as described in the “Extended Mode” section of the manual (which also shows complete list of special sequences)
    3. regular expression mode = most powerful, but most complicated; described in “Regular Expressions” section.

    So that’s a good place to start learning.

    Also, as @Ekopalypse pointed out, you didn’t make clear what you want for “before” and “after”. Please read the advice below for a better way to show your data and explain what you want.

    ----

    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 plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipbpard 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

    I apologize if I was unclear.

    After each <td ><p class=“d”> is a cell with diferent amounts of lines (the one I’ staring at now has 21 wrapped lines) and each of the 500+ pages has average 20 cells vertically in a 3 column format.

    My idea in the original post was for it to wipe out every td in the cells (column 2) I want eliminated along with the td’s of the next column, however it would replace those td’s. I did this so it knows where to stop.

    Problem is every cell has different material.
    Does that make sense?



  • @Kirk-Lauritzen making even more clear, it is

    <td><p class=“d”> different text different text</p></td>
    <td><p class=“b”>…

    By adding the next columns beginning it only deletes cell “d”’, and then I replace the ‘marker’ which is the beginning code for cell “b”.

    Even if every cell had the same text in it (which it does not) it would be too long th to stick in the find/replace box.
    Does that make better sense?



  • @Kirk-Lauritzen said in Find in files, Replace!:

    wipe out every td in the cells (column 2)

    If I understand correctly you have many tables, all of which are 3 columns wide with varying numbers of rows. Assuming there is a Header row (1st row generally) and a Description column (again generally the left most column) which we don’t want to clear, you are just wanting to clear the 2nd column of variable data, leaving the 3rd column variable data intact

    I made up a small table with the above description in mind Its:

    <html> 
      
    <head> 
        <title> 
            HTML td
        </title> 
    </head> 
      
    <body> 
        <h1>Clear 1st column variable data</h1> 
      
        <h2>HTML td</h2> 
      
        <table border="1" 
               width="500"> 
            <tr> 
                <th>NAME</th> 
                <th>AGE</th> 
                <th>BRANCH</th> 
            </tr> 
      
            <tr> 
                <td>BITTU</p></td> 
                <td><p class=“d”>22</p></td> 
                <td><p class=“b”>CSE</p></td> 
            </tr> 
      
            <tr> 
                <td>RAKESH</p></td> 
                <td><p class=“d”>25</p></td> 
                <td><p class=“b”>EC</p></td> 
            </tr> 
        </table> 
    </body> 
      
    </html>
    

    Note that I’ve assumed here that the <p class=...> code is ONLY on the variable data fields. You do state =d and =b so these are used to identify the correct column to clear. You will need to confirm whether that is true if you want to try my solution.

    So using the “Replace” function
    Find What:(?s)(<td><p class.+?“d”>).+?(</p></td>)
    Replace With:\1\2
    You MUST use search mode “regular expression” and have wrap around ticked. I noted you mentioned extended in your first post, however I have shown the selection “regular expression” as the mode to use. You also mentioned about a particular field as “containing 21 wrapped lines”. I’m thinking these lines are in fact only 1 line and if you were to turn off “word wrap” (in Notepad++) then that field would extend far to the right (off screen).

    There a few assumptions I’ve had to make as you have not made much very clear, as the others have stated. In fact an example, much like I produced above, would have made a significant step forward in outlining your problem and request. To go even further, you could show that same code with the relevant data removed, thus giving us a more complete picture of the before and after situation (as @PeterJones mentioned). The quotes you use around the d and b may also have been altered in copying into the NPP post so you may need to alter them in my “Find What” expression if they aren’t of the correct kind, I did copy them from your post.

    Terry


Log in to reply