Alex Rivera | Logout

What is the point behind character class intersections in Java's Regex?

Asked 2009-07-09T20:53:06.713
11

Java's Regex.Pattern supports the following character class:

[a-z&&[def]]

which matches "d, e, or f" and is called an intersection.

Functionally this is no different from:

[def]

which is simpler to read and understand in a big RE. So my question is, what use are intersections, other than specifying complete support for CSG-like operations on character classes?

(Please note, I understand the utility of subtractions like [a-z&&[^bc]] and [a-z&&[^m-p]], I am asking specifically about intersections as presented above.)

Edit
Report

1 Answer

1

I believe that particular sample is just a "proof of concept." Two intersected character classes only match a character that matches both character sets individually. The substractions you mentioned are the real practical applications of the operator.

Simply put, there is no hidden meaning.

answered 2009-07-09T21:03:03.030

Your Answer