Is there any difference practically between [a-zA-Z] and [a-z[A-Z]]?
According to java tutorial (and Pattern class javadoc):
[a-zA-Z] a through z, or A through Z, inclusive (range)
[a-d[m-p]] a through d, or m through p: [a-dm-p] (union)
Is there any difference practically between [a-zA-Z] and [a-z[A-Z]]?
According to java tutorial (and Pattern class javadoc):
[a-zA-Z] a through z, or A through Z, inclusive (range)
[a-d[m-p]] a through d, or m through p: [a-dm-p] (union)
Not much as far as I can see, other than making certain regexes easier to read. @hwnd's link to the regexx article gives good examples.
I've come up with a fairly esoteric use-case that might warrant it though: a character-class builder. You could build a character class by wrapping any number of other character classes in []
and you wouldn't have to worry about stripping []
from the various constituent classes.