2017년 6월 28일 수요일

[javascript] 문자열이 제이슨 데이터로 파싱이 가능한지에 대한 조건식 (정규식)


var text = "문자열";


if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

console.log("is jsonString");
  //the json is ok

}else{

console.log("is not jsonString");
  //the json is not ok

}







댓글 없음:

댓글 쓰기

[lunux]리눅스 폴더별 용량 확인

리눅스 폴더별 용량 확인 조회 하고자 하는 디렉토리 리스트가있는 경로로 이동후 du -h --max-depth=1