scripts/html-scraper-ajax.js
function selectorValidateAndParse(selectorRaw_) {
    const selectorRaw = selectorRaw_.trim();
    const bracketOpenPos = selectorRaw.indexOf('[');
    const bracketClosePos = selectorRaw.indexOf(']');

    let indexStr;
    let name = selectorRaw;

    // Slice selectorRaw to extract name and indexStr if submitted.
    if (bracketOpenPos > -1) {
      if (bracketClosePos === selectorRaw.length - 1) {
        indexStr = selectorRaw.slice(bracketOpenPos + 1, bracketClosePos);
        name = selectorRaw.slice(0, bracketOpenPos);
      }
      else {
        return null;
      }
    }

    // Validate that name is a css selector.
    // eslint-disable-next-line no-useless-escape
    if (!/^(#|\.)?[_a-z][\w#\-\.]*$/i.test(name)) {
      return null;
    }

    // If indexStr if submitted, validate it is an integer.
    if (indexStr) {
      if (!/^\d+$/.test(indexStr)) {
        return null;
      }
    }

    return name;
  }
function selectorValidateAndParse(selectorRaw_) {
    const selectorRaw = selectorRaw_.trim();
    const bracketOpenPos = selectorRaw.indexOf('[');
    const bracketClosePos = selectorRaw.indexOf(']');

    let indexStr;
    let name = selectorRaw;

    // Slice selectorRaw to extract name and indexStr if submitted.
    if (bracketOpenPos > -1) {
      if (bracketClosePos === selectorRaw.length - 1) {
        indexStr = selectorRaw.slice(bracketOpenPos + 1, bracketClosePos);
        name = selectorRaw.slice(0, bracketOpenPos);
      }
      else {
        return null;
      }
    }

    // Validate that name is a css selector.
    // eslint-disable-next-line no-useless-escape
    if (!/^(#|\.)?[_a-z][\w#\-\.]*$/i.test(name)) {
      return null;
    }

    // If indexStr if submitted, validate it is an integer.
    if (indexStr) {
      if (!/^\d+$/.test(indexStr)) {
        return null;
      }
    }

    return name;
  }
function selectorValidateAndParse ( selectorRaw_ ) { const selectorRaw = selectorRaw_ . trim ( ) ; const bracketOpenPos = selectorRaw . indexOf ( '[' ) ; const bracketClosePos = selectorRaw . indexOf ( ']' ) ; let indexStr ; let name = selectorRaw ; // Slice selectorRaw to extract name and indexStr if submitted. if ( bracketOpenPos > - 1 ) { if ( bracketClosePos === selectorRaw . length - 1 ) { indexStr = selectorRaw . slice ( bracketOpenPos + 1 , bracketClosePos ) ; name = selectorRaw . slice ( 0 , bracketOpenPos ) ; } else { return null ; } } // Validate that name is a css selector. // eslint-disable-next-line no-useless-escape if ( ! / ^(#|\.)?[_a-z][\w#\-\.]*$ / i . test ( name ) ) { return null ; } // If indexStr if submitted, validate it is an integer. if ( indexStr ) { if ( ! / ^\d+$ / . test ( indexStr ) ) { return null ; } } return name ; }
Validate syntax of Target Selector input.

@param {string} selectorRaw_ - CSS selector plus optional array index.
@returns {string|null} The selector name or null if invalid.
Validate syntax of Target Selector input .