Extracting specific characters from an inputted string into a variable

Hi there

I have a little function that validates whether a string entered is syntactically correct


function str_validate() {
                        var patt=/^[a-z]{3}w(prd|uat|dev)\\d{1}$/;
                        val = document.getElementById("hostname").value;
                        if ((val.length > 7) && patt.test(val)) {
                                   // do some good stuff
                        } else {
                                alert("Invalid string Name");
                                ClearForm();
                        }
                }
}

as you can see I am matching against 8 characters made up of 3 alphas, a ‘w’, a three character string of ‘prd’, ‘uat’ or ‘dev’ and then a single numeric

what i am looking to do is to extract into a variable the three character string (‘prd’, ‘uat’ or ‘dev’) so that i can use it to work with in another function …

does anybody know how I would be able to extract this part of the string (its always the 5th,6th and 7th character of the 8 charachter string)

any help would be greatly appreciated

looking around some more would back references be what im looking for (str.replace) ?? … it seems to only examples i can find of this are to replace parts of a string not to extract parts ?

got it … (if anyone’s remotely interested :))

var str = “abcwuat1”;
var newstr = str.replace(/[a-z]{3}w((uat|prd))[1-9]{1}/,“$1”);
document.write(newstr);

prints…

uat