var data = "<code>example1</code><code>example2</code>"; var reg = new RegExp("<code>([\\s\\S]*?)<\/code>","g"); var res = reg.exec(data); alert(res[1]);