function getSegments (regex, mode, str) {
  const segments = []
  let result

  while ((result = regex.exec(str)) !== null) {
    segments.push({
      data: result[0],
      index: result.index,
      mode: mode,
      length: result[0].length
    })
  }

  return segments
}
Get a list of segments of the specified mode
from a string

@param  {Mode}   mode Segment mode
@param  {String} str  String to process
@return {Array}       Array of object with segments data