regular expression repeating subexpression

Posted by Michael Z on Stack Overflow See other posts from Stack Overflow or by Michael Z
Published on 2010-06-15T03:36:47Z Indexed on 2010/06/15 3:42 UTC
Read the original article Hit count: 183

Filed under:
|

I have the following text

<pattern name="pattern1"/>
<success>success case 1</success>
<failed> failure 1</failed>
<failed> failure 2</failed>
<unknown> unknown </unknown>
<pattern name="pattern2"/>
<success>success case 2</success>
<otherTag>There are many other tags.</otherTag>
<failed> failure 3</failed>

And the regular expression <failed>[\w|\W]*?</failed> matches all the lines contains failed tag.

What do I need to to if I want to include the lines contains pattern tag as well? Basically, I want the following output:

<pattern name="pattern1"/>
<failed> failure 1</failed>
<failed> failure 2</failed>
<pattern name="pattern2"/>
<failed> failure 3</failed>

I am doing this in javascript, I do not mind of doing some intermediate steps.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex