Is there a way to specify using regex to show results not containing specific text.Something similar to
Select * from table where id not in {3,4,6};
Is there a way to specify using regex to show results not containing specific text.Something similar to
Select * from table where id not in {3,4,6};
How about simply looking for the text, and use the not operator on the result?
List<String> list = ...
list = list.stream()
.filter(string -> !string.matches("[346]")) // note the !
.collect(Collectors.toList());
In keeping with your example, consider this code:
Stream.of("13","11","3","33","3a")
.filter(s -> s.matches("(?!3$|4$|6$)\\d+"))
.forEach(System.out::println);
It will select only those strings which are pure digits, but do not match "3", "4" or "6".
The key feature of the regular expression is
(?!3$|4$|6$)
This is the negative lookahead, and it matches the exact strings "3", "4", and "6". Since it's negative, the whole expression matches when this part does not match.