Community

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

    Replace text in search results?

    Help wanted · · · – – – · · ·
    3
    4
    49
    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.
    • Steve Smith 0
      Steve Smith 0 last edited by

      In the find box, using “Find all in Current Document” displays those results in lines in “Search Results”. Is there any way to either directly edit these lines in the search results tab, and/or, find and replace text only within those search results?

      Terry R Mark Olson 2 Replies Last reply Reply Quote 0
      • Terry R
        Terry R @Steve Smith 0 last edited by Terry R

        @Steve-Smith-0 said in Replace text in search results?:

        Is there any way to either directly edit these lines in the search results tab, and/or, find and replace text only within those search results?

        Not as you might think. However if you were to read the online manual, specifically the search result area here (see paragraph which includes …Double-clicking with the mouse…) you will see that it links to the main editor window and allows you to quickly move around the file/tab based on the search results to edit that text you were searching on.

        Terry

        1 Reply Last reply Reply Quote 2
        • Mark Olson
          Mark Olson @Steve Smith 0 last edited by

          @Steve-Smith-0
          I don’t know what exactly you’re trying to do, but one generic way to find/replace only in lines that match some specification is to do regex-replace with positive forward lookahead from the start of each line for the first constraint.

          For example, if you want to find/replace all instances of the letter c with d on lines that contain ab, the regex/replace (?-si)^(?=.*ab).*\Kc for d
          would convert

          abc
          cab
          ccc
          dd ab c
          c ab
          

          to

          abd
          dab
          ccc
          dd ab d
          d ab
          
          1 Reply Last reply Reply Quote 1
          • Mark Olson
            Mark Olson last edited by

            My regex to find/replace c with d in lines containing ab was wrong, here’s the improved version:
            Replace (?-si)(?:^(?=.*ab)|(?!\A)\G).*?\Kc with d
            Should convert

            abc
            cab
            ccc
            z a c
            dd ab c
            c abcccc
            

            to

            abd
            dab
            ccc
            z a c
            dd ab d
            d abdddd
            

            whereas the regex in my previous post would only convert one c at a time from the last line.

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