Private/Get-MarkdownImage.ps1

function Get-MarkdownImage {
    <#
    .SYNOPSIS
        Finds the images in Markdown and returns where each one points to.

    .DESCRIPTION
        Returns the destination of every image in the text, with its position, so that the destination can be
        replaced. Two forms are found: the Markdown image, ![alt](destination "title"), and the HTML image,
        <img src="destination">.

        An image inside code, a fenced block or a code span, is text about an image and is left out. An image
        that takes its destination from a reference definition, ![alt][name], is not found.

        The text is expected to have line feeds as line endings, as Read-GhostPostFile returns it.

    .EXAMPLE
        Get-MarkdownImage -Markdown '![A diagram](images/diagram.png)'

        Returns one object with the destination images/diagram.png, its index 13 and its length 18.
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param(
        # The Markdown to search.
        [Parameter(Mandatory)]
        [AllowEmptyString()]
        [string] $Markdown
    )

    # Code comes first, so that it is skipped as a whole. Whatever matches an image has the group path.
    $pattern = @'
(?<code>
    ^[ ]{0,3}(?<fence>`{3,}|~{3,})[^\n]*\n(?s:.*?)(?:^[ ]{0,3}\k<fence>[`~]*[ \t]*$|\z)
  | (?<!`)(?<ticks>`+)(?!`)(?s:.+?)(?<!`)\k<ticks>(?!`)
)
| !\[(?:[^\[\]\\]|\\.|\[[^\[\]]*\])*\]
  \([ \t]*\n?[ \t]*
  (?:<(?<path>[^<>\n]*)>|(?<path>(?:[^\s()<>]|\([^\s()<>]*\))+))
  (?:\s+(?:"[^"]*"|'[^']*'|\([^()]*\)))?
  \s*\)
| <img\b[^>]*?(?<![\w-])src\s*=\s*(?:"(?<path>[^"]*)"|'(?<path>[^']*)')
'@

    $options = [System.Text.RegularExpressions.RegexOptions] 'IgnorePatternWhitespace, Multiline, IgnoreCase'

    foreach ($match in [regex]::Matches($Markdown, $pattern, $options)) {
        $path = $match.Groups['path']
        if ($path.Success) {
            [pscustomobject]@{
                Destination = $path.Value
                Index       = $path.Index
                Length      = $path.Length
            }
        }
    }
}