regexnotepad++line-breakslong-lines

Regular expression? How to break lines in Notepad++


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


Solution

  • 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.