為什麼正規表示式替換不刪除空白行?目的是下載網頁內容,保留可見內容,並刪除僅包含空格的行。
我使用以下 JSL 但無法刪除空白行?
謝謝!
u = "https://www.jmp.com/support/help/zh-cn/17.2/jmp/jsl-terminology.shtml";
txt = Load Text File( u );
a = Length( txt );
t1 = Regex( txt, "<(.[^>]{0,})>", "", globalreplace );
t2 = Regex( t1, " ", "", globalreplace );
t2 = Regex( t2, "^( {0,})\!n", "", globalreplace );
t2 = Regex( t2, "\!n\!n", "", globalreplace );基礎資料分析與建模視窗回覆: 為什麼正規表示式替換不刪除空白行?同樣的JSL可以替換這樣的空白行,不知道哪裡出了問題?
謝謝!
txt =
"-->\!n\!n\!n\!nJSL Terminology\!n\!n\!n\!n\!n\!n\!nScripting Guide > Introduction to Writing JSL Scripts > JSL Terminology";
t1 = Regex( txt, "\!n\!n+", "", globalreplace );
回覆:為什麼正規表示式替換不能刪除空白行?我使用 hex(t2) 來查看字串中還剩下什麼:
...0A0D0A0D0AE69CACE7BD91E7AB99E59CA8E590AFE794A8204A
61766153637269707420E79A84E68385E586B5E4B88BE69588E69E
9CE69C80E4BDB3E380820D0A0D0A0D0A0D0A0D0A0D0A0D0A0D0A"
0D0A 對是 CR LF 對。 \!n 是 JMP 的 LF 轉義符。我會使用這個正規表示式來匹配任意 CR 和 LF 的混合組合:
t2 = Regex( t2, "[\n\r]+", "", globalreplace );
正規表示式在轉義符中不使用 !。
回覆:為什麼正規表示式替換不能刪除空白行?....通常,我會用
t2 = Regex( t1, "[ \n\r]+", " ", globalreplace );
(字元集中也包含空格,替換字元也是空格)以使輸出更接近輸入,將空格壓縮為單一空格。 (我還刪除了其他 t2= 語句。)
Expression 2: Sum = 0; For( i = 1, i <= 10, i++, Sum += i; Sh
ow( i, Sum ); ); You can format your script in any way that you like. However, th
e script editor can also format your script for you. The Scripting Guide uses th
e script editor’s default formatting for capitalization, spaces, returns, tabs, and s
o on. See Work with the Script Editor for more information about using the scri
pt editor. Note: The only white space exception is two-character operators (suc
h as <= or ++). The operators cannot be separated by a space. 需要更多信
息?有问题?从 JMP 用户社区得到解答 (community.jmp.com). 本网站在
启用 JavaScript 的情况下效果最佳。 ";