Come è possibile utilizzare la sostituzione regex <*>?Come utilizzare regex per sostituire il testo di dt[1,"A"] con schede per ogni <*>. Ottiene il risultato a più colonne nella riga 2.

Grazie!
abc<AHREF>897"id="s897"</AHREF>
SceneggiaturaRe: Come posso usare la sostituzione regex <*>?ignora i 0,5 secondi, # linka i commenti nella JSL. Esegui il tuo test.
I commenti vanno rapidamente a male, soprattutto quando copia/incolla!
Re: Come posso usare la sostituzione regex <*>?/*
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: Come posso usare la sostituzione regex <*>?Voglio utilizzare JSL tramite JMP direttamente per ottenere il titolo della pagina e l'elenco dei collegamenti.
Ad esempio: questa pagina Web della comunità 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: Come posso usare la sostituzione regex <*>?Non so se stai ancora facendo una domanda. Se stai ancora cercando di far funzionare qualcosa, avrei bisogno di sapere cosa stai cercando di fare.
Si sta tentando di utilizzare un editor di testo per riformattare il file in un file delimitato da tabulazioni che JMP può leggere?
Re: Come posso usare la sostituzione regex <*>?Grazie Craig!
Sto usando la sostituzione regolare di "EmEditor"
<(.[^>]{0,})>Sceneggiatura:
document.selection.Replace("<(.[^>]{0,})>","\\t",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);Re: Come posso usare la sostituzione regex <*>?Ultimamente scrivo codice C. C usa \" per sfuggire a " ma JSL usa \!" per sfuggire a ".
Tutti e tre gli inside-the-string " hanno bisogno dell'escape JSL.
Re: Come posso usare la sostituzione regex <*>?Te l'avevo detto che non era testato... usa
\!"
per gli evasi"
Re: Come posso usare la sostituzione regex <*>?Grazie Craig!
Ho provato l'operazione, JSL non è riuscito a funzionare.


Re: Come posso usare la sostituzione regex <*>?Penso che tu voglia formule separate per le colonne b, c, ...
La formula della colonna b dovrebbe estrarre parte della stringa href.
La formula della colonna c dovrebbe estrarre parte della stringa id.
Le formule esatte potrebbero essere abbastanza semplici se i dati hanno la stessa forma su ogni riga. Ad esempio, se c'è sempre un numero subito prima di per la colonna b, (segue il codice non testato)
regex(a, "(\d+)", "\1")
potrebbe funzionare. Scomponendo questo schema:
- (\d+) - i genitori creano il gruppo di acquisizione \1, \d è una cifra, + è uno o più
- - testo letterale che deve seguire i numeri
- "\1" - inserisce il gruppo di acquisizione 1 nel risultato
Allo stesso modo, se il testo della colonna c è sempre identificato da id=,
regex(a,"id=\"[^\"]*\"")
potrebbe funzionare.
Questo modello usa \" tre posti per rappresentare una virgoletta all'interno di una stringa JSL racchiusa tra virgolette. Se rimuoviamo le virgolette esterne e non escludiamo quelle interne, la stringa regex che vede è<STRONG> id="[^"]*"</STRONG> che si scompone in
- incontro id= e il "
- [^"] è una classe di caratteri che corrisponde a qualsiasi carattere che NON sia a "
- * significa zero o più dei non- " personaggi
- seguito da "
Un'analisi semplice come questa di solito funziona su dati ben educati. Nel caso generale potresti aver bisogno di schemi più complicati (se potesse esserci un'altra id= stringa, ecc.).