Escape Meta Chars in Character Classes
Andreas Säger <[email protected]> Wed, 16 Dec 2015 14:01:24 +0100
| Newsgroups | gmane.comp.java.hsqldb.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Fred,
Another regexp question:
In HSQL REGEXP_SUBSTRING ...
'\s+(\d{1,2})(,(\d{1,2}))*([.:;-](\d{1,2}))*$'
... matches some white space with 1, 2 or 3 numbers made of 1 or 2
digits at the end of string.
The first number is always separated by one comma from the second.
Between the 2nd and the 3rd number there may be any one of . : ; - but
at this point I'd like to add some additional characters, say + and /
> http://docs.oracle.com/javase/tutorial/essential/regex/literals.html
tells us that
<([{\^-=$!|]})?*+.>
are meta and that we can escaped them by a preceeding backslash or
enclosed in \Q and \E
Adding a slash to the character class:
'\s+(\d{1,2})(,(\d{1,2}))*([.:;-/](\d{1,2}))*$'
> java.util.regex.PatternSyntaxException: Illegal character range near index 31
Same with an escaped slash \/ and with \Q/\E too although the slash is
not even in the above list of meta characters.
And as far as I remember from other languages, we should be able to use
unescaped characters within a character class.
Oh, while playing around and writing this mail, I found out that the
position within the character class makes a difference.
Character class
[/+.:;-] works well with unescaped meta characters
[.:;-/+] raises an error
The critical characters must not appear at the end of the class.
Did I find a minor bug or is this behaviour anywhere specified?
Thanks for reading. I can live with that.
Andreas
------------------------------------------------------------------------------