I have this text : 

```
var dimensions = "12 H x 45.3 W x 16 G"

```

Now I want to get the value for H & W. If not exists H or W put NULL value.

I tried like

```
 var result = str.split("x");
 var h = result[0].replace('H','');
 var w = result[1].replace('W','');

```

Expected result : h = 12, w = 45.3

The problem is that I can have and W first and H after : 

```
var dimensions = "45.3 W x 12 H x 16 G"

```

Expected result : h = 12, w = 45.3

I will appreciate your help.