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="pattern4"/>
<pattern name="pattern5"/>
<success>success case 3</success>
<pattern name="pattern2"/>
<success>success case 2</success>
<otherTag>There are many other tags.</otherTag>
<failed> failure 3</failed>
<pattern name="pattern3"/>
<unknown>unkown</unknown>
And the regular expression <failed>[\w|\W]*?</failed>
matches all the lines contains failed tag.
What do I need to to if I want all failed tags and the pattern tag above the failed tag. if there is no failed tag underneath a pattern tag, then the pattern tag should not be matched? 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.
edit start Almost all repliers suggest me to take a different approach. I am unsure which approach I should take. JQuery, regex or others. I am giving more information here for better decision making. The data format would change, but would not change often. The data is from a schematron validition report of file type ".SVRL" The structure of the file are have the following schema defined using "RELAX NG compact syntax"
schematron-output = element schematron-output {
attribute title { text }?,
attribute phase { xsd:NMTOKEN }?,
attribute schemaVersion { text }?,
human-text*,
ns-prefix-in-attribute-values*,
(active-pattern,
(fired-rule, (failed-assert | successful-report)*)+)+
}
the maps to active-pattern, and matches to failed-assert and successful-report respectively.
Now with additional information, which approach should I be taking? Thanks very much for helping out. :)
edit end