正規表現の置換で空行が削除されないのはなぜですか?目的は、Web コンテンツをダウンロードし、表示されているコンテンツを保持し、スペースのみの行を削除することです。
次の 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 );
(スペースも文字セットに含まれており、置換もスペースです)これにより、出力は入力に少し近づき、連続する空白が1つのスペースに圧縮されます。(他の 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 的情况下效果最佳。 ";