function x(a,b) { return a.length == b.length && /(?=.*I)(?=.*o)(?=.*w)(?=.*a)/.test(b) }; alert(x("Iowa","oIaw")); alert(x("Iowa","aIow")); alert(x("Iowa","stateIowa")); alert(x("Iowa","Io wa"));