如何使用正则表达式替换<*>?如何使用正则表达式将 dt[1,"A"] 的文本替换为每个 <*> 的制表符。它在第 2 行中获得多列结果。

谢谢!
abc<AHREF>897"id="s897"</AHREF>
脚本回复:如何使用正则表达式替换<*>?忽略 0.5 秒,# 链接 JSL 中的注释。 运行您自己的测试。
评论很快就会变坏,尤其是在复制/粘贴时!
回复:如何使用正则表达式替换<*>?/*
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>回复:如何使用正则表达式替换<*>?我想直接通过 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","");
回复:如何使用正则表达式替换<*>?我不确定你是否还在问问题。 如果您仍在尝试使某些工作正常进行,那么我需要知道您要做什么。
您是否尝试使用文本编辑器将文件重新格式化为 JMP 可以读取的制表符分隔文件?
回复:如何使用正则表达式替换<*>?感谢克雷格!
我正在使用“EmEditor”的常规替换
<(.[^>]{0,})>脚本:
document.selection.Replace("<(.[^>]{0,})>","\\t",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);回复:如何使用正则表达式替换<*>?我最近一直在写 C 代码。 C 使用 \" 转义 ",但 JSL 使用 \!" 转义 "。
所有三个 inside-the-string " 都需要 JSL 转义。
回复:如何使用正则表达式替换<*>?告诉你它未经测试......使用
\!”
对于逃跑的“
回复:如何使用正则表达式替换<*>?感谢克雷格!
我试了操作,JSL运行失败。


回复:如何使用正则表达式替换<*>?我认为您需要 b、c、... 列的单独公式
b 列的公式应该提取部分 href 字符串。
c 列的公式应该提取部分 id 字符串。
如果每行的数据形状相同,则确切的公式可能非常简单。 例如,如果在 b 列的 之前总是有一个数字,(下面是未经测试的代码)
regex(a, "(\d+)", "\1")
可能会奏效。 打破这种模式:
- (\d+) - 括号创建 \1 捕获组,\d 是一个数字,+ 是一个或多个
- - 必须跟在数字后面的文字
- "\1" - 将捕获组 1 插入结果中
类似地,如果 c 列文本始终由 id= 标识,
regex(a,"id=\"[^\"]*\"")
可能会奏效。
此模式使用 \"三地方表示由引号括起来的 JSL 字符串中的引号。 如果我们删除外部引号并取消转义内部引号,则正则表达式看到的字符串是<STRONG>id="[^"]*"</STRONG>分解为
- 匹配身份证=和"
- [^"]是一个字符类,它匹配任何不是"
- *指零个或多个非- "人物
- 其次是"
像这样的简单解析通常适用于表现良好的数据。 在一般情况下,您可能需要更复杂的模式(如果可能有另一个 id= 字符串等)。