# Search for minimum number of occurrences of a substring

**URL:** <https://community.postman.com/t/search-for-minimum-number-of-occurrences-of-a-substring/21511>\
**Category:** Help Hub\
**Tags:** tests, schemavalidation\
**Created:** [March 17, 2021, 6:20pm UTC](https://community.postman.com/t/search-for-minimum-number-of-occurrences-of-a-substring/21511 "2021-03-17T18:20:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmasoumi](https://avatars.discourse-cdn.com/v4/letter/b/45deac/32.png) [@bmasoumi](https://community.postman.com/u/bmasoumi)\
**Post date:** [March 17, 2021, 6:20pm UTC](https://community.postman.com/t/search-for-minimum-number-of-occurrences-of-a-substring/21511/1 "2021-03-17T18:20:38Z")

</div>

Hello,

The following is the Body of the response:

```
{
    "downloadTime": "2021:03:17T17:52:21Z",
    "downloadTimeStamp": 1616003541,
    "genome": "hg38",
    "chrom": "chrX",
    "start": 51657026,
    "end": 51658026,
    "dna": "tatgacgtaactatccatttatttagatcatcctcaaaaatatctcagtacaattttcagtgtatagattttgccaccttttgtgagatttatccctaagtatttcatgtttttaatgttatcatgctggtatttttatttaaatatcaaattgtttgttagtaatatatagaacggcaagtgatttttatagatatagcaagggggttttttgcagattctataggattattttatagagatgatcacatcttcatagacaaaagagacagttttacttaccgctttccaagtttttcttctgacccttttattaacattttttcttgtattattgcactagttagattaagcggtggacaacatatttgcccacttttttttcattttaagaggtaagtactcagtcttcatcactacatttcaagttacctgtaggtttttcatagatgccatttccttatcaagttgaggaagattgcttctgtttctagtttggtaagagttttaccaggaatgaatgctggatttgccaaatgatgtttctgcgtctattaaaatgactattttacaaatctgttaatattgtgaattacattgatttgtttttctaaggttaaactacctttgcattctttggtcatgatgcattatccttttccccaggtaatactggcttcgtacaatgagtcaggaaatattccatttctttaattttctggaaaaaaaattctgtgggtggcattatttcttccttatatgattagtagaatccacaagtaaatccatctgggcctttaattttctttgtggaaggttttaaagtagaagcttaatgtattgaagagtgttttaatcacctcctatttatcccattagtgagggagggattcctgcctaggtttaggcaaatggctggcgtatgacacgacaccggacacatgagactgttagcaatttattagtaatgtatactcacaacctgagagaggaggatacc"
}

```

I have 2 questions:  
1- I need to check if the “dna” contains at least 10 “Ngg” sites. That means if there are a minimum of 10 [acgt]gg sites (agg or cgg or tgg or ggg). How do I write a test for that?

2- Is the following test for validating schema correct?

```
const schema = {
  "downloadTime": "data-time",
  "genome": "{{human genome}}", //human genome is a collection level variable
  "chrom": ("chrX"|"chrY"),
};
pm.test('Schema is valid', function() {
  pm.response.to.have.jsonSchema(schema);
});

```

Many thanks for your help!

---

<div class="post-metadata">

**Author:** ![jfbriere](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jfbriere/32/8444_2.png) [@jfbriere](https://community.postman.com/u/jfbriere)\
**Post date:** [March 17, 2021, 11:59pm UTC](https://community.postman.com/t/search-for-minimum-number-of-occurrences-of-a-substring/21511/2 "2021-03-17T23:59:58Z")

</div>

Answer for the first question:

```auto
const count = (str) => {
  const re = /[acgt]gg/g;
  return ((str || '').match(re) || []).length;
}

if (count(body.dna) >= 10) {
  // found 10 or more
}

```
