Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?(?!.*\-1\t)(([^\t]+)\t(\d{4,5})\t([^\t]+)\t([^\t]+)$)|([^\t]+))
/
gm

Description

I'm trying to arrange and manipulate Notepad++ icons and make some scripts, so, after generating the list from the MenuIcons plugin, I used this RegEx to make a list with the container (folder/subfolder, the ones that have a -1 command ID) and indent all the items it contains (I'm using Python for my scripts, so it's more helpful for me). From this:

&File	-1	==>	C:\Program Files\Notepad++\Plugins\MenuIcons\EN-US\File.ico
    &New	41001	==>	C:\Program Files\Notepad++\Plugins\MenuIcons\EN-US\New.ico
    &Open...	41002	==>	C:\Program Files\Notepad++\Plugins\MenuIcons\EN-US\Open.ico

You get this:

&File
    41001 &New
    41002 &Open...

I just loved how this RegEx worked 98% exactly as I wanted (didn't find a way to make a difference with nested folders/menus... but as they have no command ID, it's just a non functional feature (and that was my SW Tester side speaking))

Hope it helps someone out there, feel free to adopt it to your needs (if you have many plugins like me, this will show only the name of it's container, as all of them have commands that repeat their ID)

Submitted by Me, myself and I (with the help from the Menu Icons plugin) - 3 years ago