Question

I have a delimiter in place that filters out symbols and numbers. My program is reading in a file and I would like to exclude some words from it but not all words. This might sound confusing but for example. If the first line in my file has the word light and the second line has the word lightning, is it possible to somehow filter out just light but keep lightning?

This is the code and delimiters I have put in place.

String delimiters = " ,*.-?|\t\r\n^;{}()[]+=<>/1234567890_";
ASCIIDataFile file = new ASCIIDataFile();
Was it helpful?

Solution

Are you using any split or replace operation with the delimiter ? You can use : the regex - "\blight\b" on the split/replace operation and it will match with "light" and not "lightning".

You can verify/test this out @ JavaScript RegExp Example

Hope this helps.

OTHER TIPS

You can use Pattern matching in java

Set<String> Word = new TreeSet<String>(); 
while((line=br.readLine()) != null) {
                            Pattern pattern = Pattern.compile("^YourString");
                            Matcher matcher = pattern.matcher(line);
                            while(matcher.find()) {
                                Word.add(line);
                            }
                        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top