Regex Parsing Bad XML

Discussion in 'Programming' started by lektrikpuke, Aug 19, 2011.

  1. #1
    I'm trying to learn to use regex and can't get the following to work quite right: <ns:(\w+)>.*<ns:\1> with the following malformed xml: <ns:enc><ns:td>third</ns:td><ns:enc> If it's on the same line (no line feeds, returns) it works (it will find the entire line, which is what I want). Note: I'm trying to find the matching malformed closing ns:enc. Any help? :cool:

    The unhappy face is supposed to be a : followed by a (
     
    lektrikpuke, Aug 19, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    post your code so far, with a sample of what your trying to find

    please use the
     and [code] tags
    PHP:
     
    MyVodaFone, Aug 20, 2011 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    <ns\w+)>.*<ns:\1>[code] that works if the xml is all on one line like: [code]<ns:enc><ns:td>third</ns:td><ns:enc>[code] It will match the entire line (like I want).  However, if the xml is: 
    [code]<ns:enc>
    <ns:td>third</ns:td>
    <ns:enc>[code] as you would expect (each node on a separate line), it does not match.
    Code (markup):
     
    lektrikpuke, Aug 20, 2011 IP
  4. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #4
    Finally figured it on my own. Thanks anyway guys. =)
     
    lektrikpuke, Aug 20, 2011 IP