cancel
Showing results for
Show  only  | Search instead for
Did you mean:
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
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
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" );
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" ),
)
)
)
)
)
)
)
)
)
);
);

Jim
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 ?

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)``
-Jarmo