Community
    • Login

    How to replace the first sting, omit the next string or character and append some text to the end?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 268 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.
    • Ramanand JhingadeR
      Ramanand Jhingade
      last edited by Ramanand Jhingade

      How to replace the first sting, omit the next string or character and append some text to the end?

      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'>-
              Suppressed foot sweat. <br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'>-
              Extreme SHYNESS. Bashful, cowardly. Children hide behind mother.
              Children don't play, just stare, have no friends. Fear strangers, stay
              in family. <br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'>-Great
              sensitiveness to cold. <br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'>-Specially
              indicated in infancy and old age. People who are backward mentally or
              physically and have a scrofulous diathesis and take cold easily. <br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'>-Adenopathy,
              alopecia, C.V.A., congenital malformations, developmental delay,
              enuresis, Hodgkin's disease, mental retardation, phobic disorders,
              prostatitis, sexual dysfunction, tonsillitis. <br></span>
      

      should become

      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; 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: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">mso-bidi-font-family:"Times New Roman";color:black'>Suppressed foot sweat. </span></td></tr></tbody></table><br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; 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: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">mso-bidi-font-family:"Times New Roman";color:black'>Extreme SHYNESS. Bashful, cowardly. Children hide behind mother.
              Children don't play, just stare, have no friends. Fear strangers, stay
              in family. </span></td></tr></tbody></table><br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; 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: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">mso-bidi-font-family:"Times New Roman";color:black'>Great
              sensitiveness to cold. </span></td></tr></tbody></table><br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; 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: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">mso-bidi-font-family:"Times New Roman";color:black'>Specially
              indicated in infancy and old age. People who are backward mentally or
              physically and have a scrofulous diathesis and take cold easily. </span></td></tr></tbody></table><br></span>
      <span
              style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:
              "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black'><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; 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: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">mso-bidi-font-family:"Times New Roman";color:black'>Adenopathy,
              alopecia, C.V.A., congenital malformations, developmental delay,
              enuresis, Hodgkin's disease, mental retardation, phobic disorders,
              prostatitis, sexual dysfunction, tonsillitis. </span></td></tr></tbody></table><br></span>
      

      I used this RegEx in the “Find” field: (?=mso-bidi-font-family:"Times New Roman";color:black'>)(?=.*\b-\b)([^<]*)(?=<br>) and this in the “replace” field: mso-bidi-font-family:"Times New Roman";color:black'><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: left; 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: left; 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> but it does not omit the hyphen - in the replacement, just before the text (since I added it between the two <span>s

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

        @Ramanand-Jhingade If I use $0 in the “replace” field also the second (unwanted) hyphen is still not omitted and if I use $2, no text is added

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

          @Ramanand-Jhingade said in How to replace the first sting, omit the next string or character and append some text to the end?:

          but it does not omit the hyphen - in the replacement, just before the text

          I think you are confusing lookaheads with actually having the cursor move. A lookahead will ONLY look at the sequence you have given it to see if the sub-expression is true. If it is true then it processes the next portion of the regex. In your case you then have a 2nd lookahead, so still the cursor hasn’t moved. Only when it reaches the ([^<]*) portion will the regex move the cursor and actually save text. This therefore means your regex saves text from the start of the mso-bidi- all the way to the last character before the first <br> encountered.

          So you need to change the regex so it doesn’t do this. One way would be to use a look behind instead. These are more restrictive (they must be of a fixed length) but based on the example you provided a look behind looks like it would work. So the Find What I would use would be:(?<=color:black'>)-([^<]*). So in this case $1 would return the text ONLY. So you could reduce some of the replacement field as not needing to return the first portion, I will leave that up to you to check and adjust.

          I also saw your 2nd post here where you were trying $0 and $2. That suggests you really don’t know how the regex groups work, and possibly don’t understand much of the regex functions available. Using $2 definitely won’t return anything as there is no 2nd capture group. The lookaheads, although inside () are not capture groups as you have them. You really need to start learning regex and it needs to start from the basics. Without the basics understood you will not be able to deal with the edits you are presenting on this forum.

          Terry

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

            Hello, @ramanand-jhingade, @terry-r and all,

            I noticed that, inside each <span>••••••</span> section there a dash ( - ) character after the > char and before each text. If this is a general rule of your text, the goal is easy : The regex mode is not even necessary :-)

            • Run this first S/R, in normal mode :

            SEARCH >-

            REPLACE ><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; 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: rgb0, 0, 0; font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">mso-bidi-font-family:"Times New Roman";color:black'>

            • Run this second S/R in normal mode

            SEARCH <br></span>

            REPLACE </span></td></tr></tbody></table><br></span>


            42a1bbdb-1faa-405e-9bdb-9845c4bac47a-image.png

            Best Regards,

            guy038

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

              @Terry-R Terrific, it worked perfectly. For your information, 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: left; 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: left; 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>

              @guy038 I have other such, similar strings (>- and <br></span>) which is why I needed a RegEx.

              I believe that other people will search online and find this “solution” which is why I am making time to post a reply.

              Thanks @Terry-R and @guy038 for your help and time!

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