[Javascript] Help with JS Replace function

Shawn Milochik ShawnMilo at Runbox.com
Sat Jan 15 08:11:19 CST 2005


Sure. You could use regular expressions.

For the <img /> situation, you could match on
something like (untested):
(<img[^>+])(>)

Replace with:
$1/$2

I'm not off to the pub, but I do have
to be at my martial arts class soon,
so if this answer is too vague, or
you don't know what a regular expression
is, post again, and I'll write up a small
working script for you when I return,
if nobody else jumps in and does it in the meantime.


Shawn



On Jan 15, 2005, at 6:36 AM, Alan Easton wrote:

> Hi All,
>
> I am trying to use JS Replce function to solve a problem I have.
>
> I have a string which is made up of HTML tags, such as img tags, table 
> tags, etc....
>
> Now, what I want to do is search the string and replace the img tags 
> with valid XHTML tags.
>
> Now that means I want to search for a "<img" tag, once that is found, 
> look for the closing img tag, which is a ">", and replce the ">" with 
> a "/>".
>
> I hope that makes sense. Does anyone have any idea how I could 
> accomplich this??
>
> Thanks,
>
> Alan...
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>




More information about the Javascript mailing list