• Login
Community
  • Login

[help] search and replace with searched + more

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 206 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.
  • A
    Alberto Zanot
    last edited by Alberto Zanot Dec 12, 2022, 2:47 AM Dec 12, 2022, 2:32 AM

    Hello! I need some help with replacing.
    I got a file cointaining some lines with values, like:

    AI_LEVEL=90
    …some other text
    AI_LEVEL=100
    …some other text
    AI_LEVEL=94
    and so on

    I would like each time i find the line “AI_LEVEL” despite of its value, i can add a new line containing “AI_AGGRESSION=1”, but keeping the AI_LEVEL value
    Like this:

    AI_LEVEL=90
    AI_AGGRESSION=1
    …some other text
    AI_LEVEL=100
    AI_AGGRESSION=1
    …some other text
    AI_LEVEL=94
    AI_AGGRESSION=1
    and so on

    Any help on this please? Thanks a lot!!

    T 1 Reply Last reply Dec 12, 2022, 2:50 AM Reply Quote 0
    • T
      Terry R @Alberto Zanot
      last edited by Dec 12, 2022, 2:50 AM

      @Alberto-Zanot said in [help] search and replace with searched + more:

      Any help on this please? Thanks a lot!!

      This can be achieved by using a regular epression (regex). If you aren’t sure on what these are there is a FAQ post called “Where to find REGular EXpressions (RegEx) documentation?”

      So using the Replace function (set search mode to regular expression) we have:
      Find What:(\x20*)(AI_LEVEL=\d+)(\R)
      Replace With:${1}${2}${3}${1}AI_AGGRESSION=1${3}
      You can hit either “Replace” for one change at a time, or “Replace All” which changes the entire tab’s contents.

      As you hadn’t enclosed your example in some code for displaying it’s possible you may have meant for some leading spaces to display. If so, they were removed by the formatting engine before the post showed. I’ve taken this into account and my regex will work if there are spaces as well as no spaces. The inserted line will be indented to the same amount.

      You may want to insert this code into regex101.com and it will describe the function of each portion. From there you may want to start learning some regex yourself.

      If you find that this does not solve the issue, then check what you posted. As I say, the posting engine can adjust some text. If this is the case, read the pinned post (Please Read This Before Posting) at the start of the Help Wanted section about how to post examples correctly.

      Terry

      A 1 Reply Last reply Dec 12, 2022, 2:58 AM Reply Quote 2
      • A
        Alberto Zanot @Terry R
        last edited by Dec 12, 2022, 2:58 AM

        @Terry-R
        Worked perfectly! Thanks a lot!!!

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