0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Power Automate Desktopで正規表現チェックをする

0
Last updated at Posted at 2026-03-18

概要

Power Automate Desktop では、文字列が特定の形式に一致するかをチェックしたい場面があります。
以下のようなケースです。

  • 6桁の数字かどうかをチェックしたい
  • 郵便番号形式かどうかをチェックしたい
  • メールアドレス形式かどうかをチェックしたい
  • 半角英数字のみかどうかをチェックしたい

このような文字列の形式チェックは、「.NET スクリプト実行 アクション」で VB.NET の正規表現(Regex) を使うとシンプルに実装できます。

本記事では、Power Automate Desktopで正規表現チェックを行う方法を紹介します。
※Power Fx を有効化した状態で説明しています。

やりたいこと

例えば、ユーザー入力値が6桁の数字かどうかを判定したいとします。

  • 260101 → True
  • 26010 → False
  • 2601010 → False
  • 260A01 → False

実装

「.NET スクリプト実行」アクションを使用し、言語には「VB.NET」を指定します。
以下のコードを記述します。

CheckResult = System.Text.RegularExpressions.Regex.IsMatch(
    CStr(UserInput).Trim(),
    "^[0-9]{6}$"
)

スクリプトパラメーター設定

入力値(In)

  • UserInput
    判定対象の文字列

出力値(Out)

  • CheckResult
    判定結果(Boolean)

よく使う正規表現チェック例

以下は、Power Automate Desktopの「.NETスクリプト実行(VB.NET)」でそのまま使えるサンプルです。

郵便番号チェック

ResultCheck = System.Text.RegularExpressions.Regex.IsMatch(
    CStr(InValue).Trim(),
    "^\d{3}-?\d{4}$"

半角英数字 + アンダーバー + ハイフンチェック

ResultCheck = System.Text.RegularExpressions.Regex.IsMatch(
    CStr(InValue).Trim(),
    "^[A-Za-z0-9_-]+$"

メールアドレス形式チェック(簡易版)

ResultCheck = System.Text.RegularExpressions.Regex.IsMatch(
    CStr(InValue).Trim(),
    "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"

電話番号チェック(ハイフンあり)

ResultCheck = System.Text.RegularExpressions.Regex.IsMatch(
    CStr(InValue).Trim(),
    "^\d{2,4}-\d{2,4}-\d{3,4}$"
)

まとめ

Power Automate Desktopで文字列形式をチェックしたい場合は、「.NET スクリプト実行(VB.NET)」と「Regex.IsMatch」を使うとシンプルに実装できます。

標準アクションだけでは少し表現しづらい入力チェックも、正規表現を使うことでコンパクトに実装できます。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?