Search code examples
regexnotepad++

Make a new line after 3 character after regex


I have following list:

Intel(USA)
Pfizer(USA)6
GeneralElectric(USA)43
Alphabet(Google)(USA)

I can select latest ( in each line by ^.*\K\((?=[^(]*$) regex.
Now I want to make a new line after 3 character after my regex.
for example I get following result:

Intel(USA
)  
Pfizer(USA
)6  
GeneralElectric(USA
)43  
Alphabet(Google)(USA
)  

how to do this by regex and what changes I must apply to my regex?
Note that for some reason I must create a regex for latest ( and can't use latest ) and note that provide regex for Notepad++


Solution

  • You can match until the last ( and then match optional chars other than ( and )

    Then forget what is matched so far, and assert the closing )

    In the replacement use a newline.

    ^.*\([^()\r\n]*\K(?=\))
    

    Regex demo

    Or match 3 chars A-Z

    ^.*\([A-Z]{3}\K(?=\))
    

    Regex demo

    enter image description here