Click to See Complete Forum and Search --> : regex replace


ToonMariner
08-22-2006, 08:47 AM
Hello all...

I need to perform a regular expression string replacement.

I have this :

str = str.replace('/<div class="imgcont" id="x'+id+'">(.)*<\/div>/i','');

But obviously its not working...

the initial str is the entire contents of a div and that looks like:

<div id="cont">
<div class="imgcont" id="x1">
// all manner of content in here...
</div>
<div class="imgcont" id="x2">
// all manner of content in here...
</div>
</div>

Now as there is all manner of content I can easily see why I may have to use something like..

str = str.replace('/<div class="imgcont" id="x'+id+'">(.)*<div class="imgcont">/i','');

but I suspect the issue here is the new lines in the str.

I don't want the regex to be greedy - not sure if js regex's are or not but any tips would be greatly appreciated..

thanks.

A1ien51
08-22-2006, 09:54 AM
because you have a string since you have it in single quotes. You need to build the reg exp with the RegExp object: http://www.regular-expressions.info/javascript.html

Eric