안녕하세요, 일치시켜야 하는 텍스트 문자열이 있는데 pat match()를 시도했지만 이해가 되지 않습니다.텍스트는 파일 이름입니다. 특정 패턴으로 모든 파일을 식별해야 합니다.
"AB0007 25092019 0822.txt":
2 대문자. "AB"는 실제로 항상.
4자리 숫자와 공백
ddMMYYYY(또는 8자리 숫자) 및 공백
4자리
".txt"
나는 시도했지만 많은 최신 버전에서 실패했습니다.
file="AB0007 25092019 0822.txt" // 테스트용; 결국 그것은 내가 순환하는 파일 목록의 항목이 될 것입니다.
패턴="AB"+"\d{4}"+"\s"+"\d{8}"+"\s"+"\d{4}";
pat match(file,pattern);
도움을 주시면 감사하겠습니다!
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;정규식(파일, "^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의 정규식은 패턴 일치 함수 위에 구축됩니다. 어느 쪽도 다른 쪽보다 빠르지 않습니다. 그만큼 PatRegex 함수는 정규식을 동등한 패턴 일치 함수로 변환하므로 PatMatch가 작동합니다.