Last active
May 30, 2023 14:43
-
-
Save cpuuntery/ac785fd80299eb09f0a117f02f3e3743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.\adb.exe shell am broadcast -a clipper.get | foreach {[regex]::match($_,'(?<=data=").*(?="$)').value} (Any line that does not match the regex will exist as an empty line in the output) | |
$String = .\adb.exe shell am broadcast -a clipper.get | |
[regex]::matches($String, '(?<=data=").*(?="$)').Value (The slightly longer version does not have the issue of the shorter version) | |
in powershell match returns an array of matched results | |
foreach is needed to iterate over the array | |
foreach {[regex]::match($_,'(?<=FullName=).*?(?=})').value} | |
replace only returns the the replaced string. note that regex is supported | |
cat file.txt | % {$_ -replace "find", "replace"} | |
you can pipe the replace method into another replace method just like you can pipe sed into another sed | |
| % {$_ -replace "C:\\", "file:///C:/"} | % {$_ -replace "\\", "/"} | |
When using Back Referencing with powershell regex you need to escape the dollar sign ($) by adding backtick(`) before it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment