Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to delete leading white/blank spaces in each line which begins with `<`

    Help wanted · · · – – – · · ·
    4
    8
    67
    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.
    • Ramanand Jhingade
      Ramanand Jhingade last edited by

      I read the matter here: Delete-blank-lines-of-multiple-opened-files/5 and want to ask, "How to delete leading white/blank spaces in each line which begins with < "

      PeterJones 1 Reply Last reply Reply Quote 0
      • guy038
        guy038 last edited by

        Hello, @ramanand-jhingade,

        I’m wondering : How a line which begins with the < character can have leading blank chars ( space / tab ) !?

        BR

        guy038

        Alan Kilborn 1 Reply Last reply Reply Quote 0
        • Alan Kilborn
          Alan Kilborn @guy038 last edited by

          @guy038

          I’m sure what is meant is that a bunch of whitespace leads off a line, then a < occurs, and the OP just wants to get rid of the whitespace before the < but ugh, how many of these infinite regex questions of an easy nature are we going to have to endure here?

          1 Reply Last reply Reply Quote 1
          • PeterJones
            PeterJones @Ramanand Jhingade last edited by

            @Ramanand-Jhingade ,

            You have been given at least 5 previous freebies – one for each of the Topics you have started. You have also been repeatedly pointed to advice on how to ask questions, and references for where to learn regex.

            Please show some effort: show that you’ve read the docs, show what you’ve tried, show your data, and ask targeted questions if there’s something you’re not understanding. But repeatedly asking us to do your job/homework for you is not a good way to get help.

            1 Reply Last reply Reply Quote 2
            • guy038
              guy038 last edited by guy038

              Hi, @ramanand-jhingade, @alan-kilborn, @peterjones and All,

              Not difficult, indeed ! So, with the @alan-kilborn’s interpretation, use the following regex S/R :

              SEARCH ^\h+(?=<)

              REPLACE Leave EMPTY

              As usual, tick the Wrap around option, select the Regular expression search mode and click on the Replace All button

              Best Regards,

              guy038

              Ramanand Jhingade 1 Reply Last reply Reply Quote 0
              • Ramanand Jhingade
                Ramanand Jhingade @guy038 last edited by Ramanand Jhingade

                @guy038 said in How to delete leading white/blank spaces in each line which begins with &#x60;<&#x60;:

                ^\h+(?=<)

                @guy038
                For example, I had this:-

                      <P
                      </p
                       <li
                       </li
                      </a
                      <a href
                      </span
                      <span
                     <ul
                     </ul
                    <ol
                    </ol
                      <div
                      </div
                      <br
                       <U
                       </u
                  <H3
                  </h3
                   <h1
                   </h1
                    <h2
                    </h2
                     <h4
                     </h4
                      <h5
                      </h5
                

                Using your regex, it became:-

                      <P
                      </p
                      <li
                      </li
                      </a
                      <a href
                      </span
                      <span
                      <ul
                      </ul
                      <ol
                      </ol
                      <div
                      </div
                      <br
                      <U
                      </u
                      <H3
                      </h3
                      <h1
                      </h1
                      <h2
                      </h2
                      <h4
                      </h4
                      <h5
                      </h5
                

                but I want it to be:-

                <P
                </p
                <li
                </li
                </a
                <a href
                </span
                <span
                <ul
                </ul
                <ol
                </ol
                <div
                </div
                <br
                <U
                </u
                <H3
                </h3
                <h1
                </h1
                <h2
                </h2
                <h4
                </h4
                <h5
                </h5
                

                All the leading white spaces / blank spaces should disappear but it should happen only for the lines which begin with a <

                PeterJones 1 Reply Last reply Reply Quote 0
                • PeterJones
                  PeterJones @Ramanand Jhingade last edited by PeterJones

                  @Ramanand-Jhingade ,

                  I copied the data you showed, then used the regex that @guy038 provided, and I got exactly the data that you desired.

                  It works for me.

                  You either didn’t use the same example data that you gave to us, or there is something else going on that we cannot see.

                  With View > Show Symbol > Show All Characters active, I started with
                  ecb7de33-2c6a-4f02-8942-7710c25038e7-image.png
                  and ended up with
                  2363077e-9524-4dbb-a011-1c12471dcdcf-image.png

                  BTW: once again, your example data didn’t follow all my advice, so I’ll include my advice again. Notice how it highly recommends showing data that should change and showing data that shouldn’t change. (Guy’s expression works for your data, and will properly avoid ones that don’t start with <, but your test data won’t prove that to yourself)

                  ----

                  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.

                  Ramanand Jhingade 1 Reply Last reply Reply Quote 0
                  • Ramanand Jhingade
                    Ramanand Jhingade @PeterJones last edited by

                    @PeterJones It worked for the files in my folder. Thanks!
                    @guy038 I thank you also. You are terrific - the Regex Guru as some are calling you!
                    @Alan-Kilborn I searched online and could not find a solution which is why I asked here. Please don’t get irritated. Thanks!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Copyright © 2014 NodeBB Forums | Contributors