function parseRegExp(regExpText) {
    const charList = [];

    regExpText.split("").reduce((state, char, index) => {
        if (!state.escapeNextChar) {
            if (char === "\\") {
                return Object.assign(state, { escapeNextChar: true });
            }
            if (char === "[" && !state.inCharClass) {
                return Object.assign(state, { inCharClass: true, startingCharClass: true });
            }
            if (char === "]" && state.inCharClass) {
                if (charList.length && charList[charList.length - 1].inCharClass) {
                    charList[charList.length - 1].endsCharClass = true;
                }
                return Object.assign(state, { inCharClass: false, startingCharClass: false });
            }
        }
        charList.push({
            text: char,
            index,
            escaped: state.escapeNextChar,
            inCharClass: state.inCharClass,
            startsCharClass: state.startingCharClass,
            endsCharClass: false
        });
        return Object.assign(state, { escapeNextChar: false, startingCharClass: false });
    }, { escapeNextChar: false, inCharClass: false, startingCharClass: false });

    return charList;
}
function parseRegExp(regExpText) {
    const charList = [];

    regExpText.split("").reduce((state, char, index) => {
        if (!state.escapeNextChar) {
            if (char === "\\") {
                return Object.assign(state, { escapeNextChar: true });
            }
            if (char === "[" && !state.inCharClass) {
                return Object.assign(state, { inCharClass: true, startingCharClass: true });
            }
            if (char === "]" && state.inCharClass) {
                if (charList.length && charList[charList.length - 1].inCharClass) {
                    charList[charList.length - 1].endsCharClass = true;
                }
                return Object.assign(state, { inCharClass: false, startingCharClass: false });
            }
        }
        charList.push({
            text: char,
            index,
            escaped: state.escapeNextChar,
            inCharClass: state.inCharClass,
            startsCharClass: state.startingCharClass,
            endsCharClass: false
        });
        return Object.assign(state, { escapeNextChar: false, startingCharClass: false });
    }, { escapeNextChar: false, inCharClass: false, startingCharClass: false });

    return charList;
}
function parseRegExp ( regExpText ) { const charList = [ ] ; regExpText . split ( "" ) . reduce ( ( state , char , index ) => { if ( ! state . escapeNextChar ) { if ( char === "\\" ) { return Object . assign ( state , { escapeNextChar : true } ) ; } if ( char === "[" && ! state . inCharClass ) { return Object . assign ( state , { inCharClass : true , startingCharClass : true } ) ; } if ( char === "]" && state . inCharClass ) { if ( charList . length && charList [ charList . length - 1 ] . inCharClass ) { charList [ charList . length - 1 ] . endsCharClass = true ; } return Object . assign ( state , { inCharClass : false , startingCharClass : false } ) ; } } charList . push ( { text : char , index , escaped : state . escapeNextChar , inCharClass : state . inCharClass , startsCharClass : state . startingCharClass , endsCharClass : false } ) ; return Object . assign ( state , { escapeNextChar : false , startingCharClass : false } ) ; } , { escapeNextChar : false , inCharClass : false , startingCharClass : false } ) ; return charList ; }
Parses a regular expression into a list of characters with character class info.
@param {string} regExpText The raw text used to create the regular expression
@returns {Object[]} A list of characters, each with info on escaping and whether they're in a character class.
@example

parseRegExp('a\\b[cd-]')

returns:
[
{text: 'a', index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false},
{text: 'b', index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false},
{text: 'c', index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false},
{text: 'd', index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false},
{text: '-', index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false}
]
Parses a regular expression into a list of characters with character class info . @param { string } regExpText The raw text used to create the regular expression @returns { Object [] } A list of characters each with info on escaping and whether they re in a character class . @example
Parses a regular expression into an array of tokens