privacy.sexy | Open-source tool to enforce privacy & security best-practices on Windows and macOS, because privacy | Privacy library
kandi X-RAY | privacy.sexy Summary
kandi X-RAY | privacy.sexy Summary
Enforce privacy & security best-practices on Windows and macOS, because privacy is sexy .
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of privacy.sexy
privacy.sexy Key Features
privacy.sexy Examples and Code Snippets
Community Discussions
Trending Discussions on privacy.sexy
QUESTION
I'm looking for a regex to match here strings in PowerShell @'...'@
and @"..."@
are here strings
Rules:
- Always new line is followed after start(
@'
or@"
) - There's no character after end (
'@
or"@
), it always is at the line start, however more text can follow it up - The outer
@' .. '@
may include an inner@" "@
but in this case the outer will be matched.
Examples
- Example where outer (including
hello
) will be matched
ANSWER
Answered 2021-Sep-08 at 03:48You're better off using PowerShell's language parser, System.Management.Automation.Language.Parser
, rather than a regex-based solution.[1]
I'm assuming you're always interested in the outer here-string, not one that happens to be nested inside another.
Assuming a file file.ps1
with the following verbatim content:
QUESTION
I'm trying to match PowerShell dash comments (# ...
) but not inline comments (<# .. #>
) in same regex. How can I achieve it?
I'd like to match PowerShell comments (using hashtag comment syntax). So simply everything after #
is commented out. I use #(.*$)/gm
for it.
Test-cases where the regex match is written inside brackets [..]
:
Write-Host "Hello world" [# comment here]
[# A line with only comment]
Comment without whitespace[#before]
[Comment with whitespace [#after ]
However what I'd like to use here is have an exception for "inline comments syntax". Inline comments in PowerShell looks like lorem <# inline comment #> ipsus
.
So here I'm looking for exclusions for:
Write-Host "Hello world" <# inline comment here #>
<# A line with only inline comment #>
Comment without whitespace<#no whitespace#>around
Inline comment <# in middle #> of line
Comment with whitespace #comment with >
Comment with whitespace #comment with <
Comment with whitespace #comment with <# test #>
I tried to use [^<>]
for something like #[^<>](.*[^<>]$)
but it did not work for all cases given in the above.
My progress on regex101 until I got stuck.
WhyI'm parsing PowerShell in JavaScript/TypeScript runtime to be able to inline them to run them in batch (cmd
) for a community driven open-source project. I know there will be exceptions to this (like strings with dashes inside) but I trade off simple regex parsing for robustness.
Thank you!
...ANSWER
Answered 2021-Oct-05 at 10:11I suggest checking for <
before a #
char and convert all negated character classes into negative lookarounds to avoid crossing over line boundaries:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install privacy.sexy
🌍️ Online: https://privacy.sexy.
🖥️ Offline: Check releases page, or download directly for: Windows, macOS, Linux.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page