Skip to content

Instantly share code, notes, and snippets.

@felquis
Created October 4, 2012 16:37
Show Gist options
  • Save felquis/3834826 to your computer and use it in GitHub Desktop.
Save felquis/3834826 to your computer and use it in GitHub Desktop.
Busca por string em uma string que representa um JSON.
// Buscar o que?
var busquePor = '',
json = "{1:'Ofelquis',2:'Diego',3:'Vanessa',4:'Rennan',5:'Thiago',6:'André',7:'Caio',8:'Vagner',9:'Lucio',10:'Dhiego'}",
regex = RegExp('[^{:,]+:[\'"]([^\'"]*' + busquePor + '[^\'"]*)[\'"]', 'gi'),
html = '';
json.match(regex).forEach(function (a) {
html += a+'<br />';
});
document.write(html);
/*
DEMO: http://jsbin.com/efuvuw/5/edit
Por: Ofelquis(@felquis), Diego(@diegolopeslima)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment