정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.일치하는 문자열 부분을 모두 추출하려고 하는데 정규식 일치를 사용하고 있어 원하는 "BWA005, BWAZ006"을 얻을 수 없습니다.
ex="Select Where( :\!"BWA\!"n == \!"BWA005\!" | :\!"BWA\!"n == \!"BWAZ006\!" )";
Regex match( ex, "[\!"](BWA|BWAZ|BWAZ_)([0-9]{1,})(.*?)[\!"]" )
자동화 및 스크립팅맥 OSRe: 정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.이것이 최선의 해결책은 아니라고 확신하지만 Regex Match()는 Python의 re.findall처럼 내가 원하는 작업을 수행하지 않는 것 같습니다. 이 조잡한 스크립트로 모든 일치 목록을 얻을 수 있습니다. 누군가가 더 나은 방법을 알고 있기를 바랍니다.
Names Default To Here( 1 );
ex = "Select Where( :\!"BWA\!"n == \!"BWA005\!" | :\!"BWA\!"n == \!"BWAZ006\!" )";
matchlist = {};
While( !Is Missing( Regex( ex, "(BWA|BWAZ|BWAZ_)(\d{1,})" ) ),
a = Regex( ex, "(BWA|BWAZ|BWAZ_)(\d{1,})" );
Insert Into( matchlist, a );
Substitute Into( ex, a, "" );
);
Re: 정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.실제로 { "BWA005", "BWAZ006", "BWA005" }와 같이 보고 싶은 중복 항목이 있는 경우 대신 다음과 같은 방법으로 수행하는 것이 좋습니다.
Names Default To Here( 1 );
ex = "Select Where( :\!"BWA\!"n == \!"BWA005\!" | :\!"BWA\!"n == \!"BWAZ006\!" )";
matchlist = {};
While( !Is Missing( Regex( ex, "(BWA|BWAZ|BWAZ_)(\d{1,})" ) ),
a = Regex( ex, "(BWA|BWAZ|BWAZ_)(\d{1,})" );
Insert Into( matchlist, a );
b = Contains( ex, a );
c = Length( a );
ex = Substr( ex, b + c );
);Re: 정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.감사합니다 ! 효과가있다!
이 작업을 수행하는 더 좋은 방법이 있는지 알고 싶습니다.
Re: 정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.JSL의 향후 유지관리자에게 더 좋습니까, 아니면 컴퓨터에 더 좋습니까, 아니면 다른 조치가 더 좋습니까? 여기에 몇 가지 아이디어가 있습니다. 나는 부분적으로 텍스트 문자열이 아닌 JSL 표현식으로 시작했다고 생각하기 때문에 첫 번째 것에 의지합니다.
댓글과 나무 보기 및 숲 보기에 대한 참고 사항: 내 댓글은 트리 수준입니다. 그들은 당신의 목표(숲)를 설명하는 것이 아니라 나무를 설명합니다. 미래에 JSL을 유지 관리하는 사람은 두 종류를 모두 원할 것입니다. 포리스트 수준 설명에서는 이러한 가치에 대해 생각하는 이유를 설명해야 합니다. 트리 수준은 명확하지 않은 코드가 어떻게 작동하는지에 관한 것입니다.
ex = "Select Where( :\!"BWA\!"n == \!"BWA005\!" | :\!"BWA\!"n == \!"BWAZ006\!" )";
// write(ex) // Select Where( :"BWA"n == "BWA005" | :"BWA"n == "BWAZ006" )
// Regex match( ex, "[\!"](BWA|BWAZ|BWAZ_)([0-9]{1,})(.*?)[\!"]" )
// desired result: "BWA005,BWAZ006"
//
// it isn't 100% clear what the rules are. These examples make different assumptions.
// assume the text is valid JSL that can be parsed back into an expression
// below, also assumes | but not & and no nested parens
expression = Parse( ex ); // Select Where( :BWA == "BWA005" | :BWA == "BWAZ006" )
// get the argument of the select where(...)
expression = Arg( expression, 1 ); // :BWA == "BWA005" | :BWA == "BWAZ006"
// assume there are only | (or) operators, change x|y|z => {x,y,z}
Substitute Into( expression, Expr( Or() ), {} ); // {:BWA == "BWA005", :BWA == "BWAZ006"}
result = {}; // accumulate answer in a result list
// process the expression list
For Each( {op}, expression, // :BWA == "BWA005" etc.
// the Right Hand Side of :BWA == "BWA005" is "BWA005"
RHS = Arg( Name Expr( op ), 2 ); // assign(:BWA,"BWA005"), want 2nd arg
// apply the test to see if this is one to keep
If( !Is Missing( Regex( RHS, "(BWA|BWAZ|BWAZ_)([0-9]+)" ) ),
Insert Into( result, Arg( op, 2 ) ); // yes: keep it in the result list
);
);
// join the list of RHS strings, separated by commas
Show( Concat Items( result, "," ) ); // Concat Items(result, ",") = "BWA005,BWAZ006";
<BR />// alternate example<BR /><BR />
// assume the strings can't collide with column names, perhaps because no
// column name has a suffix number and all strings do have a suffix number
result = {};
Pat Match(
ex,
// this is the pattern; it repeats as long as it can
Pat Repeat(
// either match the BWA... pattern, in quotes, stashing the regex match into the result:
( "\!"" + Pat Regex( "(BWA|BWAZ|BWAZ_)([0-9]+)" ) >> result[N Items( result ) + 1] + "\!"" )
// >> is the patImmediate() operator that copies the LHS match into the RHS location
// the list is initially 0 items long, and [nitems+1] extends the list by one more item
| // OR the alternative...
Pat Len( 1 ) // advance one character. This is how most of the text is matched.
)
);
Show( Concat Items( result, "," ) ); // Concat Items(result, ",") = "BWA005,BWAZ006";
// you *could* write a pattern match that would parse the text as an expression,
// but that is what the first example did.Re: 정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.Regex Match에는 소원이 있습니다
패턴이 겹치지 않는 모든 항목을 찾으려면 Regex Match()에 플래그를 추가하세요 . 수행하려는 작업(+ 이유 및 위치)에 따라 이를 처리하는 다양한 옵션이 있지만(이미 언급한 몇 가지 예: 루프 및 jmp 자체 패턴 일치) 사용 사례에 더 적합한 옵션이 더 있을 수 있습니다.
Re: 정규식: 일치하는 문자열의 모든 부분을 가져올 수 없습니다.Jmp18을 사용하면 Python의 re.findall을 사용하는 것이 훨씬 쉬워졌습니다.
ex="Select Where( :\!"BWA\!"n == \!"BWA005\!" | :\!"BWA\!"n == \!"BWAZ006\!" )";
Python send(ex);
Python Submit ("
import re
matches = re.findall(r'(BWA|BWAZ)([0-9]+)',ex)
");
Python get (matches)