정규식 대체가 빈 줄을 제거하지 않는 이유는 무엇입니까?목적은 웹 콘텐츠를 다운로드하고, 보이는 콘텐츠를 유지하고, 공백만 있는 줄을 제거하는 것입니다.
다음 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 的情况下效果最佳。 ";