LoginSignup
0
0

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > 正規表現 > P[0-9][0-9]TL[0-9]_draw の確認 > TRegEx::IsMatch()

Last updated at Posted at 2016-06-16
動作確認
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

860個近くあるコンポーネントの設定読込みを実装している。
その中でコンポーネント名を元にFindComponents()を使っている。

誤ったコンポーネントに対する処理を回避する一つの方法として正規表現を使ってみた。

  • #include <System.RegularExpressions.hpp> 追加
  • TRegEx::関数()を使用
Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <System.RegularExpressions.hpp>

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    //

    bool res;
    String msg;

    res = TRegEx::IsMatch(L"P01TL1_draw", L"P[0-9][0-9]TL[0-9]_draw");
    msg = BoolToStr(res);
    OutputDebugString(msg.c_str());

    res = TRegEx::IsMatch(L"PABTL1_draw", L"P[0-9][0-9]TL[0-9]_draw");
    msg = BoolToStr(res);
    OutputDebugString(msg.c_str());

}
//---------------------------------------------------------------------------

1つめはtrue、2つめはfalseとなって意図した通りになった。

正規表現の実装方法は以下などに詳しい。色々あるようだ。
http://ht-deko.com/tech064.html

こちらではIDEの標準状態で使えるものとして上記を使用した。

こちらでもmatchできるようだ

最終的にチェックしたかったのは以下の形式となった。

  • P\d{2}(T|B)(L|R)\d_draw
0
0
0

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