• Login
Community
  • Login

How to change 1 of the 2 exact same lines in text file using find and replace

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 366 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.
  • B
    Batuhan Hınçal
    last edited by Batuhan Hınçal Jul 24, 2020, 4:29 PM Jul 24, 2020, 4:28 PM

    Hello i have encountered a problem
    i have 2 of these exact couple of lines

    				<!--Team Block-->
    					<div class="col-lg-4 col-md-6 col-sm-12">
                                    ...some unnecessary code...
    				<!--Team Block-->
    					<div class="col-lg-4 col-md-6 col-sm-12">
    

    like this
    but i want to add a class to only the first line using find and replace, unfortunetly it changes the second line like first one but i dont want this to happen (yes i can do that by hand, but i have around 2000 copies of them and my time gap is narrow)
    im sorry my english is really bad and my subject is really confusing .

    P 1 Reply Last reply Jul 24, 2020, 5:00 PM Reply Quote 0
    • P
      PeterJones @Batuhan Hınçal
      last edited by Jul 24, 2020, 5:00 PM

      @Batuhan-Hınçal ,

      Can’t you just click REPLACE once, instead of REPLACE ALL, and it will just find the first instance?
      I guess that won’t work if you’re using the Find in Files dialog.

      • FIND = (?s)\A^(.*?<div class="col-lg-4 col-md-6 col-sm-12)(">)
      • REPLACE = $1 newClass$2
      • REPLACE ALL (or, presumably, REPLACE IN FILES)

      will change

      <!--Team Block-->
      <div class="col-lg-4 col-md-6 col-sm-12">
      ...some unnecessary code...
      <!--Team Block-->
      <div class="col-lg-4 col-md-6 col-sm-12">
      

      to

      <!--Team Block-->
      <div class="col-lg-4 col-md-6 col-sm-12 newClass">
      ...some unnecessary code...
      <!--Team Block-->
      <div class="col-lg-4 col-md-6 col-sm-12">
      

      caveat emptor

      This regex seemed to work for me, based on my understanding of your issue, and is published here to help you learn how to do this. I make no guarantees or warranties as to the functionality for you. You are responsible to save and backup all data before and after running this regex.

      B 2 Replies Last reply Jul 24, 2020, 7:54 PM Reply Quote 4
      • B
        Batuhan Hınçal @PeterJones
        last edited by Jul 24, 2020, 7:54 PM

        @PeterJones Really Thanks for your suggestion i’am really new into notepad++, i’ll try it right now.

        1 Reply Last reply Reply Quote 0
        • B
          Batuhan Hınçal @PeterJones
          last edited by Jul 24, 2020, 8:02 PM

          @PeterJones it worked, you’re a big man with big heart you saved me precious hours of my time

          I wish a lot of people help you in your life, god bless you.

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