Regular expression? How to break lines in Notepad++

786 views Asked by At

I'm translating an ugly formatted lang file of a plugin. It's really uncomfortable as it has no line breaks at all.

How do I enter \n after } and most of all after "text":"text",

Example of what the code looks like:

{"dir":"ltr","editor":"Rich Text Editor","common":{".........

I'm new to regex and find it difficult to learn these operators :D

4

There are 4 answers

2
npinti On BEST ANSWER

To me this looks like JSON. If this is the case, simply:

  1. Install the JSTool plugin.
  2. Paste your string/open the file containing your string.
  3. Go to Plugins -> JSTool -> JSFormat.

Given this string:

{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}

It yields:

{
    "glossary" : {
        "title" : "example glossary",
        "GlossDiv" : {
            "title" : "S",
            "GlossList" : {
                "GlossEntry" : {
                    "ID" : "SGML",
                    "SortAs" : "SGML",
                    "GlossTerm" : "Standard Generalized Markup Language",
                    "Acronym" : "SGML",
                    "Abbrev" : "ISO 8879:1986",
                    "GlossDef" : {
                        "para" : "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso" : ["GML", "XML"]
                    },
                    "GlossSee" : "markup"
                }
            }
        }
    }
}

This approach should provide you with a decent indentation as well, which should help you better make sense of what you have. Although replacing with a regular expression will work, the output could be slightly messy.

0
Whitebird On
  • Find What : }
  • Replace with: }\n

Should work after enabling Regular expression.

0
Wiktor Stribiżew On

You do not need a regular expression here, just use the Extended mode:

Find what: }

Replace with: }\n

enter image description here

1
MineSky On

Find } and replace it to }\n.
and you wanted to check "text":"text",
so find "," and replace to ",\n" will work for you.