Use regex with lookaround to spot the boundaries between JSON objects.
    Unfortunately, it has to match *something*, so at least one character
    must be removed and replaced.
357034
def detect_json_strings(raw_text):
    
    strings = re.split('}\s*(?={)', raw_text)

    # put back the stripped character
    json_strings = [string + '}' for string in strings[:-1]]

    # the last one doesn't need to be modified
    json_strings.append(strings[-1])

    return json_strings
302289
private static int jsSplitMatch(String stringValue, int startIndex,
                                  String separator) {

    if (startIndex + separator.length() > stringValue.length()) {
      return -1;
    }

    int matchIndex = stringValue.indexOf(separator, startIndex);

    if (matchIndex < 0) {
      return -1;
    }

    return matchIndex;
  }
843140
function matches(patterns) {
  if (!Array.isArray(patterns)) {
    if (typeof patterns === 'string') {
      return patterns.indexOf('!') === 0 ? [] : glob.sync(patterns);
    } else {
      return [];
    }
  }
  let result = [];
  patterns.forEach((pattern) => {
    const exclusion = pattern.indexOf('!') === 0;
    if (exclusion) {
      pattern = pattern.slice(1);
    }
    const arr = glob.sync(pattern);
    if (exclusion) {
      result = difference(result, arr);
    } else {
      result = union(result, arr);
    }
  });
  return result;
}
809090
def json_splitter(buffer):
    
    buffer = buffer.strip()
    try:
        obj, index = json_decoder.raw_decode(buffer)
        rest = buffer[json.decoder.WHITESPACE.match(buffer, index).end():]
        return obj, rest
    except ValueError:
        return None
238071
function() {
			return {
				textNode: this.textNode,
				offset: this.offset,
				character: this.textNode ? this.textNode.getText().charAt( this.offset ) : null,
				hitMatchBoundary: this._.matchBoundary
			};
		}
1374695
function checkJSONExpression(expression, json) {
  if (! (expression && json)) {
    return false;
  }

  // array expressions never match non-arrays or arrays of a different length.
  if (_.isArray(expression) && !(_.isArray(json) && expression.length === json.length)) {
    return false;
  }

  return _.all(expression, function(v, k) {

    // check "$" properties
    if (k === "$not") return (! checkJSONExpression(v, json));
    if (k === "$unordered") {
      return v.length === json.length && arrayContains(json, v);
    }
    if (k === "$contains") {
      return arrayContains(json, v);
    }
    if (k === "$length" ) return(v === json.length);
    if (k === "$gt") return (json > v);
    if (k === "$gte") return (json >= v);
    if (k === "$lt") return (json < v);
    if (k === "$lte") return (json <= v);

    // check $not-exists
    if (! _.has(json, k)) return (v === "$not-exists");

    // check rest of "$" values.
    if (v === "$exists") return _.has(json, k);
    if (v === "$string") return _.isString(json[k]);
    if (_.isRegExp(v)) return v.test(json[k]);
    if (_.isObject(v)) return checkJSONExpression(v, json[k]);
    if (v === "$date") {
      try {
        new Date(json[k]);
        return true;
      } catch (e) {
        return false;
      }
    }
    if (v === "$int") {
      //http://stackoverflow.com/questions/3885817/how-to-check-if-a-number-is-float-or-integer
      return (typeof json[k] === 'number' && json[k] % 1 === 0);
    }

    // check a strict equals
    return (v === json[k]);
  });
}
797334
def match(self, chars):
        """"""
        start_index = self.next_index
        for char in self:
            if char not in chars:
                self.next_index -= 1
                break
        return self[start_index:self.next_index]
1036573
function getMatchingChars(pattern) {
    pattern.lastIndex = nextchar - 1;
    var match = pattern.exec(chars);
    if (match && match.index === nextchar - 1) {
      match = match[0];
      nextchar += match.length - 1;
      /* Careful!  Make sure we haven't matched the EOF character! */
      if (input_complete && nextchar === numchars) {
        // Oops, backup one.
        match = match.slice(0, -1);
        nextchar--;
      }
      return match;
    } else {
      throw new Error("should never happen");
    }
  }
872433
def match_rstring(self, tokens, item):
        """"""
        name, suffix = tokens
        return self.match_mstring((None, name, suffix), item, use_bytes=suffix.startswith("b"))
1055519
function escapeJsonQuotes(json) {
      return JSON.stringify(json)
        .replace(/'/g, "&amp;apos;")
        .replace(/"/g, "&amp;quot;")
        /**
         * Codepen was unescaping &lt; (<) and &gt; (>) which caused, on some demos,
         * an unclosed elements (like <md-select>).
         * Used different unicode lookalike characters so it won't be considered as an element
         */
        .replace(/&amp;lt;/g, "&#x02C2;") // http://graphemica.com/%CB%82
        .replace(/&amp;gt;/g, "&#x02C3;"); // http://graphemica.com/%CB%83
    }
67251
function match( o, p, strict ) {

        var o_type = get_type( o ),
            p_type = get_type( p );

        if ( strict ) {

            // In strict mode, objects must have the same type
            if ( o_type !== p_type ) { return false; }

            switch( o_type ) {

                case 'array':
                    return match_arrays( o, p, true );

                case 'boolean':
                    return o === p;

                case 'nan':
                case 'null':
                case 'undefined':
                    return true;

                case 'function':
                case 'number':
                case 'regexp':
                case 'string':
                    return o.toString() === p.toString();

                case 'object':
                    return match_objects( o, p, true );

            }

        } else {

            switch( p_type ) {

                case 'array':
                    return o_type === 'array'
                                ? match_arrays( o, p, false )
                                : false;

                case 'boolean':
                case 'number':
                case 'string':
                    return p == o;

                case 'function':
                    return !!p( o );

                case 'nan':
                    return isNaN( o );

                case 'null':
                case 'undefined':
                    return o_type === p_type;

                case 'object':
                    return o_type === 'object'
                                ? match_objects( o, p, false )
                                : false;

                case 'regexp':
                    return o_type === 'string' && p.test( o );

            }

        }

    }
776641
def _get_span(s, pattern):
    """"""
    i, j = -1, -1

    match = pattern.match(s)
    if not match:
        return i, j

    for group_name in pattern.groupindex:
        i, j = match.span(group_name)
        if (i, j) != (-1, -1):
            return i, j

    return i, j
457650
private static String match(String headerLine, String token) {
    if (headerLine == null) {
      return null;
    }

    int match = headerLine.indexOf(token);
    if (match <= 0) {
      return null;
    }

    // = to skip
    match += token.length() + 1;
    int trailingComa = headerLine.indexOf(",", match);
    String value = headerLine.substring(match, trailingComa > 0 ? trailingComa : headerLine.length());
    value = value.length() > 0 && value.charAt(value.length() - 1) == '"'
            ? value.substring(0, value.length() - 1)
            : value;
    return value.charAt(0) == '"' ? value.substring(1) : value;
  }
1273765
def _boundary_value(self) -> str:
        
        # Refer to RFCs 7231, 7230, 5234.
        #
        # parameter      = token "=" ( token / quoted-string )
        # token          = 1*tchar
        # quoted-string  = DQUOTE *( qdtext / quoted-pair ) DQUOTE
        # qdtext         = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
        # obs-text       = %x80-FF
        # quoted-pair    = "\" ( HTAB / SP / VCHAR / obs-text )
        # tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
        #                  / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
        #                  / DIGIT / ALPHA
        #                  ; any VCHAR, except delimiters
        # VCHAR           = %x21-7E
        value = self._boundary
        if re.match(self._valid_tchar_regex, value):
            return value.decode('ascii')  # cannot fail

        if re.search(self._invalid_qdtext_char_regex, value):
            raise ValueError("boundary value contains invalid characters")

        # escape %x5C and %x22
        quoted_value_content = value.replace(b'\\', b'\\\\')
        quoted_value_content = quoted_value_content.replace(b'"', b'\\"')

        return '"' + quoted_value_content.decode('ascii') + '"'
297539
function(str){
    var lines = str.match(/\n/g)
      , idx = str.lastIndexOf('\n');

    if (lines) this.lineno += lines.length;
    this.column = ~idx
      ? str.length - idx
      : this.column + str.length;
  }
839871
def json_escape_string(s)
      return s if s !~ /["\\\b\f\n\r\t]/

      result = ""
      s.split("").each do |c|
        case c
        when '"', "\\"
          result << "\\" << c
        when "\n" then result << "\\n"
        when "\t" then result << "\\t"
        when "\r" then result << "\\r"
        when "\f" then result << "\\f"
        when "\b" then result << "\\b"
        else
          result << c
        end
      end
      result
    end
727260
function (s,reviver) {
        // Replace certain Unicode characters that are otherwise handled
        // incorrectly by some browser implementations.
        // NOTE: This modifies the input if such characters are found!
        s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);
        
        // Test for any remaining invalid characters
        if (!_UNSAFE.test(s.replace(_ESCAPES,'@').
                            replace(_VALUES,']').
                            replace(_BRACKETS,''))) {

            // Eval the text into a JavaScript data structure, apply any
            // reviver function, and return
            return _revive( _eval('(' + s + ')'), reviver );
        }

        throw new SyntaxError('JSON.parse');
    }