• Login
Community
  • Login

Remove all but specific phrase/line containing changing value.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 3 Posters 1.6k 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.
  • J
    jrdn bautista
    last edited by Oct 15, 2023, 10:42 AM

    Hi, I am trying to find all the database index values from a websites source code and delete all other text/code in the document so I am only left with the values.


    Here is the data I currently have (“before” data):
    [wall of code]
    data-index="1034823\
    [wall of code]
    data-index="1031769\
    [wall of code]
    data-index="1030975\
    [wall of code]
    data-index="1028228\

    Here is how I would like that data to look (“after” data):
    1034823

    1031769

    1030975

    1028228


    I am kind of new to notepad++ and I couldn’t get my head to wrap around this one. I would appreciate the help!

    A J 3 Replies Last reply Oct 15, 2023, 11:03 AM Reply Quote 0
    • A
      Alan Kilborn @jrdn bautista
      last edited by Oct 15, 2023, 11:03 AM

      @jrdn-bautista:

      Try:

      Find: (?s).*?data-index="(\d+)\\
      Replace: ${1}\r\n\r\n
      Search mode: Regular expression

      Have your caret at top-of-file and press the Replace All button.

      1 Reply Last reply Reply Quote 2
      • J
        jrdn bautista @jrdn bautista
        last edited by Oct 15, 2023, 11:23 AM

        Hi, i tried this but instead of giving just the values it deleted all of the text. Could this be because all of the code is on a single line? The code only appears to be in a single line in Notepad++, not other text editors.

        A 1 Reply Last reply Oct 15, 2023, 11:50 AM Reply Quote 0
        • G
          guy038
          last edited by guy038 Oct 15, 2023, 11:47 AM Oct 15, 2023, 11:44 AM

          Hello, @jrdn-bautista,

          When you start a new post, preferably click on the < / > button, on top of the posting window and replace the selected code_text zone with your present text. this will encapsulate all your text in a grey box which prevents the posting engine from possibly altering the text as it tries to format the post !

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn @jrdn bautista
            last edited by Alan Kilborn Oct 15, 2023, 11:50 AM Oct 15, 2023, 11:50 AM

            @jrdn-bautista said in Remove all but specific phrase/line containing changing value.:

            Hi, i tried this but instead of giving just the values it deleted all of the text. Could this be because all of the code is on a single line?

            If I put all of your “before” text on a single line, what I provided still works just fine, for me.

            Suggest you follow the FAQ for posting questions such as yours, in order to adequately convey all circumstances of your problem.

            1 Reply Last reply Reply Quote 0
            • J
              jrdn bautista @jrdn bautista
              last edited by Oct 15, 2023, 11:51 AM

              Here is the raw code if anyone is willing to take a look, would really appreciate it:

              pastebin com/JkEyygEV

              1 Reply Last reply Reply Quote 0
              • G
                guy038
                last edited by guy038 Oct 15, 2023, 12:37 PM Oct 15, 2023, 12:04 PM

                Hi, @jrdn-bautista, @alan-kilborn and All,

                You should have posted your text like that :

                [wall of code]
                data-index=\"1034823\"
                [wall of code]
                data-index=\"1031769\"
                [wall of code]
                data-index=\"1030975\"
                [wall of code]
                data-index=\"1028228\"
                

                Thus, :

                • Move on top of your file

                • Open the Replace dialog ( Ctrl + H )

                The search regex S/R becomes :

                • SEARCH (?s-i).*?data-index=\\"(\d+)\\"

                • REPLACE ${1}\r\n\r\n

                • Search mode = Regular expression

                • Click on the Replace All button

                Here you are !

                BR

                guy038

                J 1 Reply Last reply Oct 15, 2023, 12:13 PM Reply Quote 4
                • J
                  jrdn bautista @guy038
                  last edited by Oct 15, 2023, 12:13 PM

                  This worked! Sorry for the mistype, I just pasted directly from the code and I didn’t know what to edit to make it work correctly. Thank you!!

                  A 1 Reply Last reply Oct 15, 2023, 12:17 PM Reply Quote 1
                  • A
                    Alan Kilborn @jrdn bautista
                    last edited by Oct 15, 2023, 12:17 PM

                    @jrdn-bautista said in Remove all but specific phrase/line containing changing value.:

                    I just pasted directly from the code and I didn’t know what to edit to make it work correctly

                    This is why we have that FAQ entry.

                    J 1 Reply Last reply Oct 15, 2023, 12:47 PM Reply Quote 0
                    • J
                      jrdn bautista @Alan Kilborn
                      last edited by Oct 15, 2023, 12:47 PM

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      9 out of 10
                      • First post
                        9/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors