Thread: regular expression for matching XML

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    188

    regular expression for matching XML

    hmmm, there isn't a "general" forum for questions so i figure i'll post here.

    i'm monitoring traffic with winpcap and i want to parse out all XML messages. when the data comes in i filter everything out so that only ASCII characters are parsed, so that takes care of all the extra crap.

    here's the regex string i'm using

    Code:
    <(-[A-Za-z0-9:]+)[- &/:;'\.="]*>.*</\1>
    it seems to work, but there might be some cases i'm missing. any ideas? thanks.
    Last edited by bling; 11-04-2008 at 06:25 PM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by bling View Post
    hmmm, there isn't a "general" forum for questions...
    You are right, there are two.

    And this question has been asked several times, so be a good sport and utilize the search function.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    sorry my bad

    i searched the i only found 1 match:
    http://cboard.cprogramming.com/showt...ight=xml+regex

    however, that doesn't match a SOAP envelope header...actually what i posted doesn't either...
    the namespace attribute doesn't match...

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Drats... I remember one that had links to some pretty nice reg-ex libraries.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    ooops, i found the error (the 2nd part only takes special characters but not regular alphanumerics, the following appears to be working:

    Code:
    <([-:\w]+)[-:=\s"/\.\w]*>.*</\1>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  3. Regular Expression
    By tintifaxe in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2006, 07:16 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Regular Expression Troubles
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2002, 04:21 PM