There aren't lookbehinds, or inline modifiers in JavaScript RE. So we move the (?i)
to the end of the regexp: //i
. The lookbehind is a bit harder to mimic, so its easier to just accept the fact that it can't be done and instead use a capture group to find what you need:
var pattern = />([^<]+)<\/TD>/i;
var result = str.match(pattern);
// the match you want is in result[1]
EDIT: Seems to work fine on both strings you provided:
"<td class='asd'>sd</td>".match(/>([^<]+)<\/TD>/i)
// [">sd</td>", "sd"]
If you want to match multiple items in the same string you can abuse the replace()
method something like this:
var textInTds = []; // empty array we will fill up:
"<td>bla1</td><td class='asd'>sd</td>".replace(/>([^<]+)<\/TD>/ig, function($0, $1) {
textInTds.push($1); // push onto the array
return $0; // return the original text so that it doesn't destroy the string
});
// textInTds -> ["bla1", "sd"]