从文本中删除包含数字的字符串你好,
这是一种使用 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 );