src/main/java/com/basistech/tclre/Lex.java
boolean brenext(char pc) throws RegexException {
        char c = pc;

        switch (c) {
        case '*':
            if (lasttype(Compiler.EMPTY) || lasttype('(') || lasttype('^')) {
                return retv(Compiler.PLAIN, c);
            }
            return ret('*');
        case '[':
            //CHECKSTYLE:OFF
            if (have(6) && charAtNow() == '[' 
                && charAtNowPlus(1) == ':' 
                && (charAtNowPlus(2) == '<' || charAtNowPlus(2) == '>') 
                &&  charAtNowPlus(3) == ':'
                &&  charAtNowPlus(4) == ']' 
                &&  charAtNowPlus(5) == ']') {
                c = charAtNowPlus(2);
                v.now += 6;
                note(Flags.REG_UNONPOSIX);
                return ret((c == '<') ? '<' : '>');
                //CHECKSTYLE:ON
            }
            intocon(L_BRACK);
            if (next1('^')) {
                v.now++;
                return retv('[', 0);
            }
            return retv('[', 1);
        case '.':
            return ret('.');

        case '^':
            if (lasttype(Compiler.EMPTY)) {
                return ret('^');
            }
            if (lasttype('(')) {
                note(Flags.REG_UUNSPEC);
                return ret('^');
            }
            return retv(Compiler.PLAIN, c);

        case '$':
            if (0 != (v.cflags & Flags.REG_EXPANDED)) {
                skip();
            }
            if (ateos()) {
                return ret('$');
            }
            if (next2('\\', ')')) {
                note(Flags.REG_UUNSPEC);
                return ret('$');
            }
            return retv(Compiler.PLAIN, c);

        case '\\':
            break;      /* see below */
        default:
            return retv(Compiler.PLAIN, c);

        }

        assert c == '\\';

        if (ateos()) {
            throw new RegexException("REG_EESCAPE");
        }

        c = charAtNowAdvance();
        switch (c) {
        case '{':
            intocon(L_BBND);
            note(Flags.REG_UBOUNDS);
            return ret('{');

        case '(':
            return retv('(', 1);

        case ')':
            return retv(')', c);

        case '<':
            note(Flags.REG_UNONPOSIX);
            return ret('<');

        case '>':
            note(Flags.REG_UNONPOSIX);
            return ret('>');

        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            note(Flags.REG_UBACKREF);
            return retv(Compiler.BACKREF, digitval(c));

        default:
            if (iscalnum(c)) {
                note(Flags.REG_UBSALNUM);
                note(Flags.REG_UUNSPEC);
            }
            return retv(Compiler.PLAIN, c);

        }
    }
boolean brenext(char pc) throws RegexException {
        char c = pc;

        switch (c) {
        case '*':
            if (lasttype(Compiler.EMPTY) || lasttype('(') || lasttype('^')) {
                return retv(Compiler.PLAIN, c);
            }
            return ret('*');
        case '[':
            //CHECKSTYLE:OFF
            if (have(6) && charAtNow() == '[' 
                && charAtNowPlus(1) == ':' 
                && (charAtNowPlus(2) == '<' || charAtNowPlus(2) == '>') 
                &&  charAtNowPlus(3) == ':'
                &&  charAtNowPlus(4) == ']' 
                &&  charAtNowPlus(5) == ']') {
                c = charAtNowPlus(2);
                v.now += 6;
                note(Flags.REG_UNONPOSIX);
                return ret((c == '<') ? '<' : '>');
                //CHECKSTYLE:ON
            }
            intocon(L_BRACK);
            if (next1('^')) {
                v.now++;
                return retv('[', 0);
            }
            return retv('[', 1);
        case '.':
            return ret('.');

        case '^':
            if (lasttype(Compiler.EMPTY)) {
                return ret('^');
            }
            if (lasttype('(')) {
                note(Flags.REG_UUNSPEC);
                return ret('^');
            }
            return retv(Compiler.PLAIN, c);

        case '$':
            if (0 != (v.cflags & Flags.REG_EXPANDED)) {
                skip();
            }
            if (ateos()) {
                return ret('$');
            }
            if (next2('\\', ')')) {
                note(Flags.REG_UUNSPEC);
                return ret('$');
            }
            return retv(Compiler.PLAIN, c);

        case '\\':
            break;      /* see below */
        default:
            return retv(Compiler.PLAIN, c);

        }

        assert c == '\\';

        if (ateos()) {
            throw new RegexException("REG_EESCAPE");
        }

        c = charAtNowAdvance();
        switch (c) {
        case '{':
            intocon(L_BBND);
            note(Flags.REG_UBOUNDS);
            return ret('{');

        case '(':
            return retv('(', 1);

        case ')':
            return retv(')', c);

        case '<':
            note(Flags.REG_UNONPOSIX);
            return ret('<');

        case '>':
            note(Flags.REG_UNONPOSIX);
            return ret('>');

        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            note(Flags.REG_UBACKREF);
            return retv(Compiler.BACKREF, digitval(c));

        default:
            if (iscalnum(c)) {
                note(Flags.REG_UBSALNUM);
                note(Flags.REG_UUNSPEC);
            }
            return retv(Compiler.PLAIN, c);

        }
    }
brenext - get next BRE token
This is much like EREs except for all the stupid backslashes and the