I have a Caml query that i must sanitize. I collect datas from a form using javascript. 
For this I map the object with the field names : 

```
...
query += Object
    .entries(fields)
    .map(([k, v]) => (('beginning' + k) in data) && (('ending' + k) in data)
        ? `<Geq><FieldRef Name='DATE_FACTURE'/><Value IncludeTimeValue='FALSE' Type='DateTime'> '${data['beginning' + k]}' <Leq><FieldRef Name='DATE_FACTURE'/><Value IncludeTimeValue='FALSE' Type='DateTime'> '${data['ending' + k]}'`
        : `<Contains><FieldRef Name="${v}" /><Value Type='Text' >'${data[k]}'</Value></Contains>`
    )
    .join(' </And> ');
query += "</Where></Query></View>";

```

This function allow me to generate the query but i want to remove the empty values. 
For example, if i send the form with only one field setted I obtain a string : 

```
<View>
    <Query> 
        <Where>
            <Contains>
                <FieldRef Name="date" /><Value Type='Text' >'undefined'</Value>
            </Contains> 
            </And> 
            <Contains>
                <FieldRef Name="FileLeafRef" />
                <Value Type='Text' >'undefined'</Value>
            </Contains> 
            </And> 
               <Contains>
                  <FieldRef Name="CODE1" /><Value Type='Text' >'undefined'</Value>
               </Contains> 
               </And> 
               <Contains>
                   <FieldRef Name="CODE2" />
                   <Value Type='Text' >'undefined'</Value>
               </Contains> 
               </And> 
               <Contains>
                   <FieldRef Name="CODE3" />
                   <Value Type='Text' >'Hello World'</Value>
              </Contains> 
        </Where>
    </Query>
</View>

```

My objective is to remove : 

```
<Contains>
    <FieldRef Name="date" /><Value Type='Text' >'undefined'</Value>
</Contains> 
</And> 
<Contains>
    <FieldRef Name="FileLeafRef" />
    <Value Type='Text' >'undefined'</Value>
</Contains> 
</And> 
<Contains>
<FieldRef Name="CODE1" /><Value Type='Text' >'undefined'</Value>
...

```

I should not have the "contains" with undefined values. 
I found out how to remove the string undefined ( (\w*undefined\w*\b) ) . But i'm stuck at this stage.