정규식 대체 <*>를 어떻게 사용할 수 있습니까?정규식을 사용하여 dt[1,"A"]의 텍스트를 각 <*>에 대한 탭으로 바꾸는 방법입니다. 행 2에 다중 열 결과가 표시됩니다.

감사!
abc<AHREF>897"id="s897"</AHREF>
스크립팅Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?0.5초 무시, # JSL의 주석 링크. 자신의 테스트를 실행합니다.
댓글은 특히 복사/붙여넣기를 할 때 빨리 나빠집니다!
Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?/*
THIS IS NOT AN HTML PARSER
HTML parsers are hard to write. There are better ways.
Neither of these JSL ideas can properly skip comments or
many other HTML tags that should be skipped. They will
find things they shouldn't and miss other things they
should find. They've only been minimally tested on one site.
This code is presented as "how can I use contains() vs patmatch()
to efficiently work through a large string looking for something?"
The second example is FIVE TIMES FASTER and a LITTLE MORE ACCURATE.
The third example uses text explorer to grab links. I don't think
there is a pre-existing regex for the link text descriptions. It works
very similar to this code; it is NOT an HTML parser either.
If you can use python, you might want to investigate "beautiful soup".
I've not used it, but believe it addresses the "hard to write" issue.
*/
u = "https://community.jmp.com/t5/Discussions/bd-p/discussions";
txt = Load Text File( u );
// a link on a page has at least two parts:
// the URL and some descriptive text.
// <A ...="" href="https://community.jmp.com/url" ...="" target="_blank" rel="nofollow noopener noreferrer"> descripton </A>
// p1 p4 p5
// to parse ALL the links on a page, you'll want
// some sort of loop. There are many ways to
// write that loop; here are two choices
// using contains and regex. "<A>", p1 + 3 ); // find the end of the opening tag
p5 = Contains( txt, "</A>", p4 + 1 ); // find the ending tag
if( p5 > p4, // as long as the end is not zero, we found one, see break() below
desc = Substr( txt, p4 + 1, p5 - p4 - 1 ); // the visible link description. Images can be here too.
desc = Regex( desc, "<[^>]*>", "", globalreplace ); // remove span, image, etc tags
linktext = Substr( txt, p1, p4 - p1 + 1 ); // <A href="https://community.jmp.com/" target="_blank">
hreftext = Regex( linktext, "href\s*=\s*(\!"|')(.*?)(\1)", "\2" );// use regex to get the href value
if( !Is Missing( hreftext ), // sometimes there isn't one
dt << addrows( 1 );//
irow = N Rows( dt );//
dt:link[irow] = hreftext;//
dt:description[irow] = desc; //
);//
, // else
Break() // no more end tags. there is maybe a mess of javascript.
);//
pos = Max( pos, p5 + 3 ); // advance past the one just found
Wait( 0 );
);
stoptime = Tick Seconds();
dt << endDataUpdate;
Show( stoptime - starttime ); // .5 sec, 127 links
// using pattern matching and regex
// this is about 5X faster and skips over the garbage in the <SCRIPT> sections
// two patterns, one for &amp;amp;amp;lt;a&amp;amp;amp;gt; links and one for &amp;amp;amp;lt;script&amp;amp;amp;gt; to skip over
linkpat = "&amp;amp;amp;lt;a " + Pat Break( "&amp;amp;amp;gt;" ) &amp;amp;amp;gt;&amp;amp;amp;gt; linktext + "&amp;amp;amp;gt;" + Pat Arb() &amp;amp;amp;gt;&amp;amp;amp;gt; desctext + "&amp;amp;amp;lt;/a&amp;amp;amp;gt;";
scriptpat = "&amp;amp;amp;lt;script" + Pat Break( "&amp;amp;amp;gt;" ) + "&amp;amp;amp;gt;" + Pat Arb() + "</SCRIPT>";
dt = New Table( "patmatch", New Column( "description", Character, "Nominal" ), New Column( "link", Character, "Nominal" ) );
Wait( .1 );
dt << beginDataUpdate;
startTime = Tick Seconds();
rc = patmatch( txt,
patrepeat( // repeat the pattern until no more
(linkpat + pattest(// run some JSL for the linkpat...
desc = Regex( desctext, "<[^>]*>", "", globalreplace ); // remove span, etc tags
hreftext = Regex( linktext, "href\s*=\s*(\!"|')(.*?)(\1)", "\2" );//
if( !Is Missing( hreftext ), //
dt << addrows( 1 );//
irow = N Rows( dt );//
dt:link[irow] = hreftext;//
dt:description[irow] = desc; //
);//
1; // pattest needs this to succeed
)) | scriptpat /* maybe skip a script */ | /* maybe skip to the next tag */ (Pat Len( 1 ) + Pat Break( "<" ))
),
NULL,IGNORECASE
);
stoptime = Tick Seconds();
dt << endDataUpdate;
Show( stoptime - starttime ); // .5 sec, 128 links
Show( rc ); // should be 1, not 0
///////////////////////////////////////
// text explorer can also do this:
dt=New Table( "textexplorer",
Add Rows( 1 ),
New Column( "text", Character, "Nominal", Set Values( evallist({txt}) ) )
);
dt<<TEXT explorer=""></TEXT></A>Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?JMP를 통해 JSL을 직접 사용하여 페이지 제목과 링크 목록을 얻고 싶습니다.
예: 이 JMP 커뮤니티 웹 페이지,

u="https://community.jmp.com/t5/Discussions/bd-p/discussions";txt=loadtextfile(u);
t1="";offset=Contains(txt,t1);
If(offset,txt=SubStr(txt,offset+4,Length(txt)));
t2="";offset=Contains(txt,t2,-1);
If(offset,txt=SubStr(txt,1,offset-1));
txt=Substitute(txt," ","","message">","","Discussions/","Discussions/>");
txt=Substitute(txt,"<(.[^>]{0,})>","","\!n","","\!r","");
Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?아직도 질문을 하시는지 모르겠네요. 당신이 여전히 무언가를 작동시키려고 한다면, 나는 당신이 무엇을 하려고 하는지 알아야 할 것입니다.
텍스트 편집기를 사용하여 JMP가 읽을 수 있는 탭으로 구분된 파일로 파일을 다시 포맷하려고 하십니까?
Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?Craige 감사합니다!
저는 "엠에디터"의 일반 대체품을 사용하고 있습니다.
<(.[^>]{0,})>스크립트:
document.selection.Replace("<(.[^>]{0,})>","\\t",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?최근에 C 코드를 작성하고 있습니다. C는 \"를 사용하여 "를 이스케이프하지만 JSL은 \!"를 사용하여 "를 이스케이프합니다.
문자열 내부의 세 가지 " 모두 JSL 이스케이프가 필요합니다.
Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?테스트되지 않았다고 말했는데... 사용
\!"
탈출을 위해"
Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?Craige 감사합니다!
작업을 시도했지만 JSL이 실행되지 않았습니다.


Re: 정규식 대체 <*>를 어떻게 사용할 수 있습니까?b, c, ... 열에 대해 별도의 수식을 원한다고 생각합니다.
b열의 수식은 href 문자열의 일부를 추출해야 합니다.
열 c의 수식은 id 문자열의 일부를 추출해야 합니다.
데이터가 모든 행에서 동일한 모양이면 정확한 공식은 매우 간단할 수 있습니다. 예를 들어, 열 b의 바로 앞에 항상 숫자가 있는 경우(테스트되지 않은 코드가 뒤따름)
regex(a, "(\d+)", "\1")
작동할 수 있습니다. 해당 패턴을 분해:
- (\d+) - 괄호는 \1 캡처 그룹을 생성하고, \d는 숫자이고, +는 하나 이상입니다.
- - 숫자 뒤에 와야 하는 리터럴 텍스트
- "\1" - 캡처 그룹 1을 결과에 삽입
마찬가지로 열 c 텍스트가 항상 id=로 식별되는 경우
regex(a,"id=\"[^\"]*\"")
작동할 수 있습니다.
이 패턴은 \" 삼 장소 따옴표로 묶인 JSL 문자열 내부의 따옴표를 나타냅니다. 외부 따옴표를 제거하고 내부 따옴표를 이스케이프 해제하면 regex가 보는 문자열은 다음과 같습니다.<STRONG> 아이디="[^"]*"</STRONG> 로 분해
- 성냥 아이디= 그리고 "
- [^"] 가 아닌 모든 문자와 일치하는 문자 클래스입니다. "
- * 0 또는 그 이상을 의미합니다. " 캐릭터
- 뒤이어 "
이와 같은 간단한 구문 분석은 일반적으로 잘 작동하는 데이터에서 작동합니다. 일반적인 경우 더 복잡한 패턴이 필요할 수 있습니다(다른 id= string 등이 있을 수 있는 경우).