Power Automate Desktopの、フローを整形するフローです。
クリップボード上で処理します。
# [ControlRepository][PowerAutomateDesktop] 以降のJSON部分を処理します。
整形内容
- 改行
- セレクタの要素名の、シングルクォーテーション部分を削除
- スクリーンショット削除(
ScreenShot/ScreenshotPathをnullにする)
PADフロー整形.robin
Clipboard.GetText Text=> ClipboardText
Text.ParseText.RegexParseForFirstOccurrence Text: ClipboardText TextToFind: $'''(?m)^(?=\\{\\s+\"ControlRepositorySymbols\": \\[)''' StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position
IF Position = (-1) THEN
EXIT Code: 0
END
Text.GetSubtext.GetSubtextFromStartTo Text: ClipboardText NumberOfChars: Position Subtext=> Robin
Text.GetSubtext.GetSubtextFrom Text: ClipboardText CharacterPosition: Position Subtext=> Json
Text.Replace Text: Json TextToFind: $'''(?<=\\\\r\\\\n)''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''\\n ''' ActivateEscapeSequences: True Result=> Json
Text.Replace Text: Json TextToFind: $'''(?m)(?<=^ {21,}\\\\\"Name\\\\\": \\\\\"[^\'\\n]+) \'.+\'(?=\\\\\")''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> Json
Text.Replace Text: Json TextToFind: $'''(?m)(?<=^\\s+\\\\\"ScreenShot\\\\\": )\\\\\"[^\"]+\\\\\"''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''null''' ActivateEscapeSequences: False Result=> Json
Text.Replace Text: Json TextToFind: $'''(?m)(?<=^\\s+\\\\\"ScreenshotPath\\\\\": )\\\\\"[^\"]+\\\\\"''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''null''' ActivateEscapeSequences: False Result=> Json
Clipboard.SetText Text: $'''%Robin%%Json%'''
使っている正規表現をメモしておきます。
リファレンスは正規表現言語 - クイック リファレンス - .NET | Microsoft Learn。
確認はregex101の.NET(C#) FLAVOR が便利です。
改行
(?<=\\r\\n)
シングルクォーテーション部分
(?m)(?<=^ {21,}\\"Name\\": \\"[^'\n]+) '.+'(?=\\")
ScreenShot
(?m)(?<=^\s+\\"ScreenShot\\": )\\"[^"]+\\"
ScreenshotPath
(?m)(?<=^\s+\\"ScreenshotPath\\": )\\"[^"]+\\"