Search code examples
regexreplacecopynotepad++

Notepad++ - How to mass copy numbers at the beginning of lines to another part of each line?


So I'm looking for a faster way to mass reformat some files for a game.

I have code like this:

84045 = {
    name = Sam
    dynasty = 3
    dna = kfsdiofjsoidfj
    culture = example
    religion = example
    martial = 10
    diplomacy = 10
    stewardship = 10
    intrigue = 10
    learning = 10
    add_trait = trait
    add_trait = trait
    add_trait = trait

    father = 84042
    1395.6.7 = {birth = ""}
    1449.6.7 = {death = ""}
}

What I need relates to this part:

    1395.6.7 = {birth = ""}
    1449.6.7 = {death = ""}

So I have hundreds of these entries. What I want is for the numbers like "1395.6.7" to be mass copied and entered into the quote marks, with the result like this:

    1395.6.7 = {birth = "1395.6.7"}
    1449.6.7 = {death = "1449.6.7"}

How can I do this in Notepad++ (or potentially some other easy way)?


Solution

    • Ctrl+H
    • Find what: ([\d.]+) = {(?:bir|dea)th = "\K(?="})
    • Replace with: $1
    • CHECK Wrap around
    • CHECK Regular expression
    • Replace all

    Explanation:

    ([\d.]+)        # group 1, 1 or more digit or dot
     = {            # literally
    (?:bir|dea)     # non capture group, bir OR dea
    th = "          # literally
    \K              # forget all we have seen until this position
    (?="})          # positive lookahead, make sure we have a quote and closing bracket after
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here