Splitting strings using multiple delimiters in java

I am working on a data mining algorithm where I need to tokenize a string using a few words. I have a separate file containing all the temporary words. I need to do this in order to tokenize the input string with any word (stopwatch) working as a delimiter. For instance,
If the file contains temporary words like
this is
and
of
what

and the input line is "a computer cluster consists of a set of loosely coupled computers that work together"
the result should be a computer cluster consists of a set
loosely coupled computers
to work together

Checking a string in all recursive seconds will be very time consuming? Is there a good method to do this?

+4
source share
1 answer

Build a regular expression of the form

delim1|delim2|delim3 

then use the String split() method to split the text into any of the delimiters.

To create a regular expression, read each separator and pass it to Pattern.quote before adding to the regular expression to be created. This will allow your delimiters to use regular expression metacharacters.

+7
source

Source: https://habr.com/ru/post/1443997/


All Articles