index.js
function (tag, text, index) {
    var re = wp.shortcode.regexp(tag)
    var match
    var result

    re.lastIndex = index || 0
    match = re.exec(text)

    if (!match) {
      return
    }

    // If we matched an escaped shortcode, try again.
    if (match[1] === '[' && match[7] === ']') {
      return wp.shortcode.next(tag, text, re.lastIndex)
    }

    result = {
      index: match.index,
      content: match[0],
      shortcode: wp.shortcode.fromMatch(match)
    }

    // If we matched a leading `[`, strip it from the match
    // and increment the index accordingly.
    if (match[1]) {
      result.content = result.content.slice(1)
      result.index++
    }

    // If we matched a trailing `]`, strip it from the match.
    if (match[7]) {
      result.content = result.content.slice(0, -1)
    }

    return result
  }
function (tag, text, index) {
    var re = wp.shortcode.regexp(tag)
    var match
    var result

    re.lastIndex = index || 0
    match = re.exec(text)

    if (!match) {
      return
    }

    // If we matched an escaped shortcode, try again.
    if (match[1] === '[' && match[7] === ']') {
      return wp.shortcode.next(tag, text, re.lastIndex)
    }

    result = {
      index: match.index,
      content: match[0],
      shortcode: wp.shortcode.fromMatch(match)
    }

    // If we matched a leading `[`, strip it from the match
    // and increment the index accordingly.
    if (match[1]) {
      result.content = result.content.slice(1)
      result.index++
    }

    // If we matched a trailing `]`, strip it from the match.
    if (match[7]) {
      result.content = result.content.slice(0, -1)
    }

    return result
  }
function ( tag , text , index ) { var re = wp . shortcode . regexp ( tag ) var match var result re . lastIndex = index || 0 match = re . exec ( text ) if ( ! match ) { return } // If we matched an escaped shortcode, try again. if ( match [ 1 ] === '[' && match [ 7 ] === ']' ) { return wp . shortcode . next ( tag , text , re . lastIndex ) } result = { index : match . index , content : match [ 0 ] , shortcode : wp . shortcode . fromMatch ( match ) } // If we matched a leading `[`, strip it from the match // and increment the index accordingly. if ( match [ 1 ] ) { result . content = result . content . slice ( 1 ) result . index ++ } // If we matched a trailing `]`, strip it from the match. if ( match [ 7 ] ) { result . content = result . content . slice ( 0 , - 1 ) } return result }
Find the next matching shortcode

Given a shortcode `tag`, a block of `text`, and an optional starting
`index`, returns the next matching shortcode or `undefined`.

Shortcodes are formatted as an object that contains the match
`content`, the matching `index`, and the parsed `shortcode` object.

@param tag
@param text
@param index
@return {*}
Find the next matching shortcode