1

Given a list of profile image links in markdown with varying name lengths:

![[Last, First.jpg]]
![[Longerlast, Longerfirst.jpg]]
etc

How can I convert to the following using regex in NPP?

![[Last, First.jpg]]
::Last, First
![[Longerlast, Longerfirst.jpg]]
::Longerlast, Longerfirst
etc

I was able to isolate the first and last patterns through trial and error, but am running into a wall before a complete solution.

2 Answers2

1

Use a regular expression replace of ^(!\[\[)(.*, *)(.*)(\.jpg\]\]) with \1\2\3\4\r\n::\2\3.

Explanation

^(!\[\[)           The front part, in capture group 1
(.*, *)            The first word and the comma space, in capture group 2
(.*)               The second word, in capture group 3
(\.jpg\]\])        The trailing part, in capture group 4

Replacement

\1\2\3\4            Reassemble the input line
\r\n                Line break
::\2\3              The second line

Note that if you do a couple of "Replace" actions to test it plus a "Replace all" then the will be a couple of duplicated outputs. To prevent that sort of thing I would normally use a replacement such as ---\1\2\3\4\r\n::\2\3 to add a marker string to the pieces that have been processed, then do another "Replace all" (in this case of ^--- with nothing) to remove those markers.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
1
  • Ctrl+H
  • Find what: ^!\[\[(.+?)\.jpg]]\K
  • Replace with: \n::$1
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • Replace all

Explanation:

^           # beginning of line
!\[\[       # literally ![[
(.+?)       # group 1, 1 or more any character, not greedy
\.jpg]]     # literally .jpg]]
\K          # forget all we have seen until this position

Replacement:

\n          # liebreak, you can use \r\n for Windows EOL
::          # ::
$1          # content of group 1 i.e. last, first

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125