cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
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

Recommended Articles