こんにちは。一致させる必要があるテキスト文字列があり、pat match() を試していますが、理解できません。テキストはファイル名です。 特定のパターンを持つすべてのファイルを識別する必要があります。
"AB0007 25092019 0822.txt":
大文字2文字。 「AB」は実際には常にです。
4桁の数字とスペース
ddMMYYYY (または 8 桁のみ) とスペース
4桁
"。TXT"
私は試みてきましたが、多くのバージョンで失敗しました、最新:
file="AB0007 25092019 0822.txt" // テスト用。最終的には、それがファイルリストの項目として循環されることになります。
pattern="AB"+"\d{4}"+"\s"+"\d{8}"+"\s"+"\d{4}";
パットマッチ(ファイル,パターン);
助けていただければ幸いです。
JSLには、正規表現従来の正規表現一致を行う関数と、パッチマッチ必要に応じて正規表現のスニペットを使用できる関数。 最後の例は、を使用する理由を示唆しています。パッチマッチ関数。また、ファイル名全体が一致することを確認するための ^...$ または PatPos(0)...PatRPos(0) ロジックの追加ビットにも注目してください。
file = "AB0007 25092019 0822.txt"; // for testing; eventually it will be an item in a file list that I cycle through
// decide if using (1) pure regex,
Show( Regex( file, "^AB\d{4}\s\d{8}\s\d{4}\.txt$" ) ); // "AB0007 25092019 0822.txt", or missing (.) if not matched
// or (2) pure pattern matching,
digit = Pat Any( "0123456789" );
pattern = Pat Pos( 0 ) + "AB" + Pat Repeat( digit, 4, 4 ) + " " + Pat Repeat( digit, 8, 8 ) + " " + Pat Repeat( digit, 4, 4 ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ) ); // rc is 1, it matches, 0 if fails to match
// or (3a) mix of both
pattern = Pat Pos( 0 ) + "AB" + Pat Regex( "\d{4}" ) + Pat Regex( "\s" ) + Pat Regex( "\d{8}" ) + Pat Regex( "\s" ) + Pat Regex( "\d{4}" ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ) ); // rc is 1, it matches, 0 if fails to match
// or collapse the mix (3b) a bit
pattern = Pat Pos( 0 ) + "AB" + Pat Regex( "\d{4}\s\d{8}\s\d{4}" ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ) ); // rc is 1, it matches, 0 if fails to match
// why you might choose (2) or (3a) -- you can capture substrings like the date part using the >> operator:
digit = Pat Any( "0123456789" );
pattern = Pat Pos( 0 ) + "AB" + Pat Repeat( digit, 4, 4 ) + " " + Pat Repeat( digit, 8, 8 ) >> datepart + " " + Pat Repeat( digit, 4, 4 ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ),informat(datepart,"ddmmyyyy") ); // rc is 1, Informat(datepart, "ddmmyyyy") = 25Sep2019;Regex(file, "^AB\d{4}\s\d{8}\s\d{4}\.txt$") = "AB0007 25092019 0822.txt";
パットマッチ(ファイル、パターン) = 1;
パットマッチ(ファイル、パターン) = 1;
パットマッチ(ファイル、パターン) = 1;
パットマッチ(ファイル、パターン) = 1;
Informat(datepart, "ddmmyyyy") = 2019 年 9 月 25 日;
JMP の正規表現は、パターン マッチング関数の上に構築されています。どちらがもう一方よりも速くなることはありません。 のパット正規表現関数は正規表現を同等のパターン マッチング関数に変換し、PatMatch が機能するようにします。