Created
October 4, 2012 16:37
-
-
Save felquis/3834826 to your computer and use it in GitHub Desktop.
Busca por string em uma string que representa um JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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