문제

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();
도움이 되었습니까?

해결책

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.

다른 팁

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);
                            }
                        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top