What I'm looking for
I would like to match hash comments excluding inline comments in PowerShell . I can match them using #(?<!<#)(?![<>])(.*)$ (see regex101). However I would want to achieve this by not using lookbehind. Is there any way I can get the same (or closest) behavior to the regex with lookbehind?
A regex only solution would be nice but I would also appreciate solutions JavaScript only solutions.
What I tried
My best was try #(?!.*>)(.*)$ (see regex101), but I'm unhappy that it misses anything that has> after #.
I also tried writing JavaScript only parsing but it got very complex (more than 30 lines, see pastebin) and was very slow.
Why I need it
I use this to inline PowerShell used in an open-source project (GitHub code). However, the project is online and runs on browser (website) and unfortunately I realized that it does not work in Safari as Safari does not yet support lookbehind (caniuse.com).
Syntax: Hash comment vs inline comment
Rule: Match all hash comments but exclude inline comments
Hash comments in PowerShell, just like in bash and other languages starts from hash (#) and continues until the end of the line.
Write-Host "Hello world" # Here is a hash comment
Inline comments in PowerShell is between <# and #>
Write-Host <# Here is an inline comment #> "Hello world"