2017-07-03 10 views
-2

は、私は1つの変数文字列の開始と終了を一致させ、文字列全体を一致した値に整形するJavaScript正規表現ですか?

文字列

{"index":"logstash-cdr","search_type":"count","ignore_unavailable":true} 
{"query":{"filtered":{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}}]}},"filter":{"bool":{"must":[{"range":{"@timestamp":{"gte":1451586600000,"lte":1483208999000,"format":"epoch_millis"}}}],"must_not":[]}}}},"size":0,"aggs":{"2":{"terms":{"field":"PhoneNumber","size":100000,"order":{"_count":"desc"}}}}} 
{"index":"logstash-cdr","ignore_unavailable":true} 
{"highlight":{"pre_tags":["@[email protected]"],"post_tags":["@/kibana-highlighted-f[email protected]"],"fields":{"*":{}},"require_field_match":false,"fragment_size":2147483647},"query":{"filtered":{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}}]}},"filter":{"bool":{"must":[{"range":{"@timestamp":{"gte":1451586600000,"lte":1483208999000,"format":"epoch_millis"}}}],"must_not":[]}}}},"size":50,"sort":[{"@timestamp":{"order":"desc","unmapped_type":"boolean"}}],"fields":["*","_source"],"script_fields":{},"fielddata_fields":["@timestamp"]} 
{"index":"logstash-fraud","search_type":"count","ignore_unavailable":true} 
{"query":{"filtered":{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}}]}},"filter":{"bool":{"must":[{"range":{"@timestamp":{"gte":1451586600000,"lte":1483208999000,"format":"epoch_millis"}}}],"must_not":[]}}}},"size":0,"aggs":{"2":{"terms":{"field":"PhoneNumber","size":100000,"order":{"_count":"desc"}}}}} 
{"index":"logstash-fraud","ignore_unavailable":true} 
{"query":{"filtered":{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}}]}},"filter":{"bool":{"must":[{"range":{"@timestamp":{"gte":1451586600000,"lte":1483208999000,"format":"epoch_millis"}}}],"must_not":[]}}}},"highlight":{"pre_tags":["@[email protected]"],"post_tags":["@/[email protected]"],"fields":{"*":{}},"require_field_match":false,"fragment_size":2147483647},"size":50,"sort":[{"@timestamp":{"order":"desc","unmapped_type":"boolean"}}],"fields":["*","_source"],"script_fields":{},"fielddata_fields":["@timestamp"]} 

内の文字列を持っているが、私はちょうど

{"index":"logstash-fraud","search_type":"count","ignore_unavailable":true} 
{"query":{"filtered":{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}}]}},"filter":{"bool":{"must":[{"range":{"@timestamp":{"gte":1451586600000,"lte":1483208999000,"format":"epoch_millis"}}}],"must_not":[]}}}},"size":0,"aggs":{"2":{"terms":{"field":"PhoneNumber","size":100000,"order":{"_count":"desc"}}}}} 

この行はどのように私にはJavaScriptを通じて同じことを達成することができ、印刷したいですか?

+0

_java-script_? JavaScriptにする必要があります。それは本当に文字列です....私はjavascriptのオブジェクトに思えます。 – Jai

+0

これを変数 –

+0

に格納しています。次に、文字列/オブジェクトまたは他の型であることをどのように知っていますか? – Jai

答えて

0

文字列を変数aに格納する場合。次のようにsubstring()メソッドを使用できます。

var start = a.indexOf('{"index":"logstash-fraud"'); 
c = a.substring(start,a.indexOf('{"index',start+1)); 
+0

logstash-cdrを持つ行が表示されています –

+0

私は答えを編集しました –

関連する問題