UiPath > メール本文から必要な情報だけを抽出する

要求 メール本文から必要な情報を抜き出して欲しい

RPAには基幹システムから自動送信されたメールを受診し、その本文の内容から必要なデータを読み込み、チェックするロボットがあります。

今回の要求は、受信されてくるメールの中から、以下のような情報を読み込んで欲しいと仮定します。

この赤枠の部分を抽出してなければならない。

ワークフロー 概要

このようなワークフローを使って、実際に文字列を抽出してみたいと思います。ポイントは「正規表現」と「一致する文字列を取得」アクティビティです。

正規表現を使って抽出する

このやり方にはいろんな抽出方法があります。例えば改行を1行1行ずつ分割するSplitメソッドの方法です。

その中でも今回は正規表現を使った抽出方法を使っていきましょう。

この赤枠で囲まれた単語は、どのような法則性を持っているでしょうか、まず一つは、先頭にコロンがついていること、そしてもう一つは最後が行末であることです。

コロンと行末の間に挟まれている任意の文字を抽出する

(?<=:).*(?=\r\n)

この正規表現を説明すると、
?<=:
コロンが前に位置している
.*
任意の文字が存在している
?=\r\n
行末が最後に位置している

正規表現チェッカーのサイトはこちらからです。
ちょっと改行のところが上手く認識しなかったので、 ドルマークで対応しています。

普通だったら正規表現ビルダーで見るんですけど、肯定否定の先読み後読みはちょっと対応していないみたいなので、正規表現チェッカーを使いました。

何も反応してくれない

一致する文字列を変数 matches で返す

「一致する文字列」アクティビティは入力した文字列を正規表現で検索し、一致した値を変数「Matches」型で変えてしてくれます。

今回は、そのMatches型を「matches」として返してみます。

「一致する文字列を取得」アクティビティを通過した後、 ローカルパネルの値を参照してみます。「matches」の中に配列として4つ格納されました。

Matches型は「0」から順番に変数の値を返してくれます。
次の代入アクティビティで「登録ID」から順番にmatches(0).ToString で返していきます。

余談 これでも、まだエラーハンドリングが足りない。

おそらく、これだけでも十分に実装することは可能でしょう。しかし、もっとテストケースを入念に行う場合、本当に「登録ID – 氏名 – 登録日時 – 登録URL」の順番なのだろうか?というケースも考えるべきです。(もしくは、システム側に問い合わせて、本当にこの順番に変動はないのか問い合わせてみてもいいかもしれません)

一応、今回はここまで。

79件のフィードバック

  1. Nice post. I was checking continuously this blog and I am
    impressed! Extremely helpful info specially the last part 🙂 I care for such information a lot.
    I was seeking this certain information for a long time.

    Thank you and best of luck.

    my homepage: vpn special coupon

  2. I’m truly enjoying the design and layout
    of your website. It’s a very easy on the eyes which makes it much
    more enjoyable for me to come here and visit more
    often. Did you hire out a designer to create your theme?
    Great work!

    Here is my web site vpn code 2024

  3. I was curious if you ever considered changing
    the structure of your website? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people
    could connect with it better. Youve got an awful lot of text for only having one or 2 pictures.

    Maybe you could space it out better?

    Have a look at my web blog – vpn special coupon code 2024

  4. You can definitely see your skills in the paintings you write. The sector hopes for more passionate writers like you who aren’t afraid to say how they believe. All the time follow your heart. “We are near waking when we dream we are dreaming.” by Friedrich von Hardenberg Novalis.

  5. Just want to say your article is as surprising. The clearness in your post is simply spectacular and i could assume you are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the gratifying work.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

目次