var str1 = "text1 content text2"; var matches = str1.match(/text1\s(\S+)\stext2\s(\S+)/); var res1 = matches[1]; var res2 = matches[2];