從文字中刪除包含數字的字串你好,
這是使用 JSL 刪除任何包含數字的字串的方法嗎?
例子:
我吃了4個蘋果和2根香蕉
型號為0998GBELS
03/45是要檢查的比率
目標輸出:
我吃了蘋果和香蕉
型號是
是要檢查的比率
自動化和腳本編寫回覆:從文字中刪除包含數字的字串我不確定這是否適用於所有情況,但它適用於這些範例
Names Default To Here(1);
strs = {
"I ate 4 apples and 2 bananas",
"the model number is 0998GBELS",
"03/45 is the ratio to check"
};
result2 = Transform Each({str}, strs,
Regex(str, "\w*\S*\d+\w*\S*", "", GLOBALREPLACE)
);
show(result2); // result2 = {"I ate apples and bananas", "the model number is ", " is the ratio to check"};
編輯:
我認為正規表示式可以稍微簡化為
Regex(str, "\S*\d+\S*", "", GLOBALREPLACE)
https://regex101.com/r/PM4UQn/1
回覆:從文字中刪除包含數字的字串我有很多行要處理(以億為單位),這樣做會導致更高的延遲。我想知道是否有更好的方法來刪除那些包含延遲較低的數字的字串?
回覆:從文字中刪除包含數字的字串這可行,但熟悉正規表示式的人可以簡化腳本
Names Default To Here( 1 );
theString = "I ate 4 apples and 2 bananas
the model number is 0998GBELS
03/45 is the ratio to check";
theList = Words( theString, " \!n\!r\!t" );
adjustedString = "";
For Each( {member}, theList,
Show( member );
//member=thelist[1]
found = "No";
If( !Contains( member, "0" ),
If( !Contains( member, "1" ),
If( !Contains( member, "2" ),
If( !Contains( member, "3" ),
If( !Contains( member, "4" ),
If( !Contains( member, "5" ),
If( !Contains( member, "6" ),
If( !Contains( member, "7" ),
If( !Contains( member, "8" ),
If( !Contains( member, "9" ),
adjustedString = Trim( adjustedString || " " || member )
)
)
)
)
)
)
)
)
)
);
);
Show( adjusted String );