cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-723579%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%BE%9E%E6%96%87%E5%AD%97%E4%B8%AD%E5%88%AA%E9%99%A4%E5%8C%85%E5%90%AB%E6%95%B8%E5%AD%97%E7%9A%84%E5%AD%97%E4%B8%B2%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-723579%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E4%BD%A0%E5%A5%BD%EF%BC%8C%3CBR%20%2F%3E%E9%80%99%E6%98%AF%E4%BD%BF%E7%94%A8%20JSL%20%E5%88%AA%E9%99%A4%E4%BB%BB%E4%BD%95%E5%8C%85%E5%90%AB%E6%95%B8%E5%AD%97%E7%9A%84%E5%AD%97%E4%B8%B2%E7%9A%84%E6%96%B9%E6%B3%95%E5%97%8E%EF%BC%9F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E4%BE%8B%E5%AD%90%EF%BC%9A%3CBR%20%2F%3E%E6%88%91%E5%90%83%E4%BA%86%3CSTRONG%3E4%E5%80%8B%3C%2FSTRONG%3E%E8%98%8B%E6%9E%9C%E5%92%8C%3CSTRONG%3E2%3C%2FSTRONG%3E%E6%A0%B9%E9%A6%99%E8%95%89%3CBR%20%2F%3E%E5%9E%8B%E8%99%9F%E7%82%BA%3CSTRONG%3E0998GBELS%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E03%2F45%3C%2FSTRONG%3E%E6%98%AF%E8%A6%81%E6%AA%A2%E6%9F%A5%E7%9A%84%E6%AF%94%E7%8E%87%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E7%9B%AE%E6%A8%99%E8%BC%B8%E5%87%BA%EF%BC%9A%3C%2FP%3E%3CP%3E%E6%88%91%E5%90%83%E4%BA%86%E8%98%8B%E6%9E%9C%E5%92%8C%E9%A6%99%E8%95%89%3CBR%20%2F%3E%E5%9E%8B%E8%99%9F%E6%98%AF%3C%2FP%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%E6%98%AF%E8%A6%81%E6%AA%A2%E6%9F%A5%E7%9A%84%E6%AF%94%E7%8E%87%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-723579%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3E%E8%87%AA%E5%8B%95%E5%8C%96%E5%92%8C%E8%85%B3%E6%9C%AC%E7%B7%A8%E5%AF%AB%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-723612%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E5%BE%9E%E6%96%87%E5%AD%97%E4%B8%AD%E5%88%AA%E9%99%A4%E5%8C%85%E5%90%AB%E6%95%B8%E5%AD%97%E7%9A%84%E5%AD%97%E4%B8%B2%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-723612%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%88%91%E4%B8%8D%E7%A2%BA%E5%AE%9A%E9%80%99%E6%98%AF%E5%90%A6%E9%81%A9%E7%94%A8%E6%96%BC%E6%89%80%E6%9C%89%E6%83%85%E6%B3%81%EF%BC%8C%E4%BD%86%E5%AE%83%E9%81%A9%E7%94%A8%E6%96%BC%E9%80%99%E4%BA%9B%E7%AF%84%E4%BE%8B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0Astrs%20%3D%20%7B%0A%22I%20ate%204%20apples%20and%202%20bananas%22%2C%0A%22the%20model%20number%20is%200998GBELS%22%2C%0A%2203%2F45%20is%20the%20ratio%20to%20check%22%0A%7D%3B%0A%0Aresult2%20%3D%20Transform%20Each(%7Bstr%7D%2C%20strs%2C%0A%09Regex(str%2C%20%22%5Cw*%5CS*%5Cd%2B%5Cw*%5CS*%22%2C%20%22%22%2C%20GLOBALREPLACE)%0A)%3B%0A%0Ashow(result2)%3B%20%2F%2F%20result2%20%3D%20%7B%22I%20ate%20apples%20and%20bananas%22%2C%20%22the%20model%20number%20is%20%22%2C%20%22%20is%20the%20ratio%20to%20check%22%7D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%E7%B7%A8%E8%BC%AF%EF%BC%9A%3C%2FP%3E%0A%3CP%3E%E6%88%91%E8%AA%8D%E7%82%BA%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%A4%BA%E5%BC%8F%E5%8F%AF%E4%BB%A5%E7%A8%8D%E5%BE%AE%E7%B0%A1%E5%8C%96%E7%82%BA%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ERegex(str%2C%20%22%5CS*%5Cd%2B%5CS*%22%2C%20%22%22%2C%20GLOBALREPLACE)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fregex101.com%2Fr%2FPM4UQn%2F1%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fregex101.com%2Fr%2FPM4UQn%2F1%3C%2FA%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-723611%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E5%BE%9E%E6%96%87%E5%AD%97%E4%B8%AD%E5%88%AA%E9%99%A4%E5%8C%85%E5%90%AB%E6%95%B8%E5%AD%97%E7%9A%84%E5%AD%97%E4%B8%B2%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-723611%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%88%91%E6%9C%89%E5%BE%88%E5%A4%9A%E8%A1%8C%E8%A6%81%E8%99%95%E7%90%86%EF%BC%88%E4%BB%A5%E5%84%84%E7%82%BA%E5%96%AE%E4%BD%8D%EF%BC%89%EF%BC%8C%E9%80%99%E6%A8%A3%E5%81%9A%E6%9C%83%E5%B0%8E%E8%87%B4%E6%9B%B4%E9%AB%98%E7%9A%84%E5%BB%B6%E9%81%B2%E3%80%82%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E6%98%AF%E5%90%A6%E6%9C%89%E6%9B%B4%E5%A5%BD%E7%9A%84%E6%96%B9%E6%B3%95%E4%BE%86%E5%88%AA%E9%99%A4%E9%82%A3%E4%BA%9B%E5%8C%85%E5%90%AB%E5%BB%B6%E9%81%B2%E8%BC%83%E4%BD%8E%E7%9A%84%E6%95%B8%E5%AD%97%E7%9A%84%E5%AD%97%E4%B8%B2%EF%BC%9F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-723591%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E5%BE%9E%E6%96%87%E5%AD%97%E4%B8%AD%E5%88%AA%E9%99%A4%E5%8C%85%E5%90%AB%E6%95%B8%E5%AD%97%E7%9A%84%E5%AD%97%E4%B8%B2%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-723591%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E9%80%99%E5%8F%AF%E8%A1%8C%EF%BC%8C%E4%BD%86%E7%86%9F%E6%82%89%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%A4%BA%E5%BC%8F%E7%9A%84%E4%BA%BA%E5%8F%AF%E4%BB%A5%E7%B0%A1%E5%8C%96%E8%85%B3%E6%9C%AC%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0AtheString%20%3D%20%22I%20ate%204%20apples%20and%202%20bananas%0Athe%20model%20number%20is%200998GBELS%0A%0A03%2F45%20is%20the%20ratio%20to%20check%22%3B%0A%0AtheList%20%3D%20Words(%20theString%2C%20%22%20%5C!n%5C!r%5C!t%22%20)%3B%0AadjustedString%20%3D%20%22%22%3B%0AFor%20Each(%20%7Bmember%7D%2C%20theList%2C%0A%09Show(%20member%20)%3B%0A%2F%2Fmember%3Dthelist%5B1%5D%0A%09found%20%3D%20%22No%22%3B%0A%09If(%20!Contains(%20member%2C%20%220%22%20)%2C%0A%09%09If(%20!Contains(%20member%2C%20%221%22%20)%2C%0A%09%09%09If(%20!Contains(%20member%2C%20%222%22%20)%2C%0A%09%09%09%09If(%20!Contains(%20member%2C%20%223%22%20)%2C%0A%09%09%09%09%09If(%20!Contains(%20member%2C%20%224%22%20)%2C%0A%09%09%09%09%09%09If(%20!Contains(%20member%2C%20%225%22%20)%2C%0A%09%09%09%09%09%09%09If(%20!Contains(%20member%2C%20%226%22%20)%2C%0A%09%09%09%09%09%09%09%09If(%20!Contains(%20member%2C%20%227%22%20)%2C%0A%09%09%09%09%09%09%09%09%09If(%20!Contains(%20member%2C%20%228%22%20)%2C%0A%09%09%09%09%09%09%09%09%09%09If(%20!Contains(%20member%2C%20%229%22%20)%2C%0A%09%09%09%09%09%09%09%09%09%09%09adjustedString%20%3D%20Trim(%20adjustedString%20%7C%7C%20%22%20%22%20%7C%7C%20member%20)%0A%09%09%09%09%09%09%09%09%09%09)%0A%09%09%09%09%09%09%09%09%09)%0A%09%09%09%09%09%09%09%09)%0A%09%09%09%09%09%09%09)%0A%09%09%09%09%09%09)%0A%09%09%09%09%09)%0A%09%09%09%09)%0A%09%09%09)%0A%09%09)%0A%09)%3B%0A)%3B%0A%0AShow(%20adjusted%20String%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
dadawasozo
Level IV

remove string that contains number from text

Hi,
 is that a way to remove any string that contain numbers using JSL?

 

Example:
I ate 4 apples and 2 bananas
the model number is 0998GBELS

03/45 is the ratio to check

 

Targeted Output:

I ate apples and bananas
the model number is 

 is the ratio to check

 

3 REPLIES 3
txnelson
Super User

Re: remove string that contains number from text

This works, but someone familiar with Regular Expressions would be able to simplify the script

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 );

 

Jim
dadawasozo
Level IV

Re: remove string that contains number from text

I have many lines to process (in hundred millions), doing so will cause higher latency. I wonder if there is a better way to remove those strings that contain number with lower latency ?

 

jthi
Super User

Re: remove string that contains number from text

Not sure i this would work in all situations but it does for these examples

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"};

Edit:

I think that regex can be simplified a bit to

Regex(str, "\S*\d+\S*", "", GLOBALREPLACE)

https://regex101.com/r/PM4UQn/1 

-Jarmo