Community
    • Login

    How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    html
    15 Posts 2 Posters 352 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.
    • Terry RT
      Terry R @Ramanand Jhingade
      last edited by

      @Ramanand-Jhingade said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:

      If I use (?<!^)(?<! )(-) it finds all the hyphens which I don’t want to happen.

      First thought is that ^\x20*- should find ONLY the hyphen at the start of each line (sentence if you want to call it that as it does seem each sentence starts on a new line).

      As for the rest, it looks like there is a great deal of repetition with some of the html code. My initial thought would be to convert that code to a special set of characters not found elsewhere, such as #@#. So your first regex could be a lot shorter and use these characters. Then a second regex would replace all occurrences of these 3 characters with the real code.

      Terry

      1 Reply Last reply Reply Quote 1
      • Terry RT
        Terry R
        last edited by

        @Terry-R said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:

        My initial thought would be to convert that code to a special set of characters not found elsewhere, such as #@#.

        Part of the reason for splitting the replacement into 2 steps is that you have a lot of replacement text to insert. I haven’t counted the amount but be mindful there is a limit to the number of characters that can be used to find strings and also that which can be replaced. Read the manual here and go down about 3 pages, looking for A valid Find what edit box entry length ranges from 1 to 2046 characters.

        Terry

        1 Reply Last reply Reply Quote 2
        • Ramanand JhingadeR
          Ramanand Jhingade
          last edited by

          @Terry-R I changed all the hyphens that I wanted to change manually to #@# and searched for (?<!^)(?<! )(#@#)([^<]*)(?=<br>) and replaced it with <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">#@#</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1</span></td></tr></tbody></table> and it worked but I still think it can be done in one step with the right Regex. I think someone needs to help me find the hyphen/s at the beginning of each line for that

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

            @Ramanand-Jhingade Sorry, I used <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">#@#</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1$2</span></td></tr></tbody></table> in the replace field - some typo

            1 Reply Last reply Reply Quote 0
            • Terry RT
              Terry R
              last edited by

              @Ramanand-Jhingade said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:

              I think someone needs to help me find the hyphen/s at the beginning of each line for that

              The regex I provided should have done that. If not then it would seem you have additional data not shown which affects the ability to target just those hyphens you want to change.

              So did you try?:
              Find What:^\x20*-([^<])*
              Replace With:<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"></span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1</span></td></tr></tbody></table> because from what I can figure with your latest post that would seem to be the combination of the first replacement and your html code insert.

              Ramanand JhingadeR 2 Replies Last reply Reply Quote 1
              • Ramanand JhingadeR
                Ramanand Jhingade @Terry R
                last edited by

                @Terry-R Your Regex above finds what it needs to perfectly but the replacement needs to improve as it does not add the text before the <br> back

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

                  This post is deleted!
                  1 Reply Last reply Reply Quote 1
                  • Ramanand JhingadeR
                    Ramanand Jhingade @Terry R
                    last edited by Ramanand Jhingade

                    @Terry-R OK, I used this in the replace field: <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$0</span></td></tr></tbody></table> and it worked!
                    Thanks a lot!
                    However, it adds the 4 spaces and the hyphen that were there originally also - any way I can avoid that (but of course, I want the text to be there after the replacement)?

                    Terry RT 1 Reply Last reply Reply Quote 0
                    • Terry RT
                      Terry R @Ramanand Jhingade
                      last edited by

                      @Ramanand-Jhingade said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:

                      However, it adds the 4 spaces and the hyphen that were there originally also

                      That’s because you have $0 which means all of the found text. Previously you had $1 which is the correct one.

                      Terry

                      Ramanand JhingadeR 3 Replies Last reply Reply Quote 1
                      • Ramanand JhingadeR
                        Ramanand Jhingade @Terry R
                        last edited by

                        @Terry-R $1 was not adding back the text after the replacement which is why I used $0. If there is a way to avoid the 4 spaces and hyphen, as well as add the text after the replacement, please let me know. If that is not possible, please tell me how to find the unwanted hyphen, just before the text that I want - I can find only the wanted hyphen with -[^A-Za-z] due to my limited knowledge of Regex

                        1 Reply Last reply Reply Quote 0
                        • Ramanand JhingadeR
                          Ramanand Jhingade @Terry R
                          last edited by

                          @Terry-R I finally used this Regex in the “Find” field: ^ *-([^<]*) and this in the “Replace” field and it worked perfectly: <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1</span></td></tr></tbody></table>
                          Thanks for your time and help!

                          1 Reply Last reply Reply Quote 0
                          • Ramanand JhingadeR
                            Ramanand Jhingade @Terry R
                            last edited by

                            @Terry-R The second * had to be within the bracket!

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