Re: Escape Meta Chars in Character Classes
Fred Toussi <[email protected]> Wed, 16 Dec 2015 14:23:36 +0000
| Newsgroups | gmane.comp.java.hsqldb.user |
|---|---|
| Message-ID | <1450275816.3941728.469077945.61F5C2D7@webmail.messagingengine.com> |
Hi Andreas
I do not write regular expressions often enough to try and comment. When
you ask a question like this, provide an example of the input and the
required output so others can try and comment on it.
You may get better answers if ask your question at StackOverflow using
HSQLDB, Java and regular expression tags.
Fred
On Wed, Dec 16, 2015, at 13:01, Andreas Säger wrote:
> 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
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Hsqldb-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hsqldb-user
------------------------------------------------------------------------------