-2

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};

rupesh jain
  • 3,410
  • 1
  • 14
  • 22

3 Answers3

1

[^346] -any character except 3,4,6. Is this what you asked?

lucian.marcuta
  • 1,250
  • 1
  • 16
  • 29
0

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());
Ypnypn
  • 933
  • 1
  • 8
  • 21
0

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.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436