Hi i have string like below,

```
apiVersion: v1
clusters:
- cluster:  <------------------------  this is one cluster
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ
    server: https://api.someaddress 
name: https://api.anotheraddress
- second_cluster:  <------------------------  this is second cluster
    certificate-authority-data: LS0tLS1
    server: https://api.someaddress
name: https://api.
contexts:
- context:  <------------------------  this is one context
    cluster: https://api.another1address
    namespace: name1           
    user: user1
 name: somename
- another_context:  <------------------------  this is second context
    cluster: https://api.anotheraddress
    namespace: esm2
    user: admin
name: somename1
current-context: some-context
kind: somekind
preferences: {}
users:
- name: user-admin
    user:
        token: eyJhb

```

how can i check if the there is more than one cluster under clusters and more than one context under contexts using regex.

i have tried something like below

```
var matchServer = new RegExp(/- cluster:\n[A-Za-z0-9\- :]*\n[ ]+server: ([A-Za-z:.//]*)/, "gi").exec(s);
const namespace = s.match(/contexts:\n- context:\n[A-Za-z0-9\- :.//]*\n[ ]+namespace: ([A-Za-z0-9]*)/i);

```

but this gives server and namespace also only one occurrence is returned.

i want to get the number of matched string "cluster" under clusters and context under contexts.

could someone help me with this. i am new to programming. thanks.

**what i have tried?**

i have tried regex to match "context" "another\_context" under contexts. but it matches only "context"

contexts:\n-.\*context:+

could someone help me understand why it doesnt match the another\_context string

**updated question:**

with the regex

const matchServer = result.match(/- [a-z\_]*cluster:[A-Za-z0-9- :\n]*[ ]+server: ([A-Za-z0-9:.//]\*)/gi);

this returns null for below string although there is server under cluster.

```
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: 
LS0tLS1CRUd
    server: https://api.sandbox1.lab.fi.eu.ericsson.se
  name: https://api.sandbox1.lab.fi.eu.ericsson.se
contexts:
- context:
    cluster: https://api.sandbox1.lab.fi.eu.ericsson.se
    namespace: esm1
    user: esm-esm1-ci-namespace-admin
  name: esm-context
current-context: esm-context
kind: Config
preferences: {}
users:
- name: esm-esm1-ci-namespace-admin
  user:
    token: 
eyJhbGc

```

why doesnt the above regex work for this string. could someone help me with this. thanks.