0

probably a silly question. I'm trying to find and replace the following code in javascript. So that code is part of an ajax response with a lot of html code. So, I'm getting the ajax response, and I put it on a string variable, and using replace() I'm trying to remove the following tags combination. Any idea will be appreciated?

    <ul> 


      </li>
    </ul>
srecce
  • 97
  • 3
  • 15

1 Answers1

0

Javascript replace uses RegEx (regular expressions)...

the pattern for your (invalid) tag-combination to remove will be:

result = subject.replace(/<ul>[\t\r\n ]*<\/li>[\t\r\n ]*<\/ul>/ig, "");

this replaces all <ul>'s, followed by an </li>, followed by an </ul> with only "newline, carriage-return, tabulator or space" between them.

TheHe
  • 2,933
  • 18
  • 22