Skip to content

Instantly share code, notes, and snippets.

@cpuuntery
Last active May 30, 2023 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpuuntery/ac785fd80299eb09f0a117f02f3e3743 to your computer and use it in GitHub Desktop.
Save cpuuntery/ac785fd80299eb09f0a117f02f3e3743 to your computer and use it in GitHub Desktop.
.\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