Intersection and Subtraction Groupings

Asked

Viewed 285 times

0

I have a question regarding regular expressions. I do not understand how intersection and subtraction work in regular expressions. Could someone enlighten me?

[a-z&&[aeiou]]  Interseção
[a-z&&[^m-p]]   Subtração
System.out.println("O QUE PODE FICAR AQUI PARA SER VERDADEIRO?".matches("[a-z&&[aeiou]]"));
System.out.println("O QUE PODE FICAR AQUI PARA SER VERDADEIRO?".matches("[a-z&&[^m-p]]"));
  • What do you want to do?

  • I’m just trying to understand these two guys.

  • 1

    You want to know if a regex catch something? if possible explain better what you want to do.

1 answer

0


As the name already says, the intersection will intersect two regular expressions. That is, the intersection of n regular expressions is a regular expression that will give match if all the n subexpressions also give match.

Subtraction of a regular expression to by an expression b will give match only if the expression to der match and the regular expression b don’t give.

In the case of the expression [a-z&&[aeiou]], to String a gives match in the sub-expression a-z and also gives match in the sub-expression [aeiou]. Soon he gives match in the expression [a-z&&[aeiou]]. On the other hand, the String b can only match in the first subexpression, and therefore it does not give match in full expression.

In the case of the expression [a-z&&[^m-p]], to String a gives match in the sub-expression a-z and also gives match in the sub-expression [^m-p] (because a is not among m and p). Soon he gives match in the expression [a-z&&[^m-p]]. On the other hand, the String m gives match in the first subexpression, but does not give match in the second because m is among m and p, and therefore he does not give match in full expression.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.