Solved

regular expressions, find text that starts with a word ends with another word but does not contain the last word.

Posted on 2003-10-27
3
1,527 Views
Last Modified: 2007-12-19
Quick one for anyone good with regular expressions.

Ok, say I have a XML file with this layout.

<event  time="23424" name="2325">
      <param name="5645645" data="1231">
      <param name="11231213" data="346">
      <param name="2351324" data="123">
</event>
<event  time="43747" name="2435">
      <param name="32452345" data="5674">
      <param name="2345" data="4567">
      <param name="2435" data="2345">
</event>

I want to use regular expressions to find blocks missing the </event> tag.

I can search and find the blocks from <event...> to the next <event...> but I can't figure out how to only list ones without </event>

Thanks
0
Comment
Question by:waynegs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
ultimatemike earned 250 total points
ID: 9633516
It's kinda tricky to do with regular expressions....Generally XML/HTML is recursive, and it's structure doesn't lend well to RE's.  Here's a perl script that does the job though - It'll print out and event tags that aren't closed:


Just change "xmlfile.xml" to whatever the filename is.


#!perl -w
use strict;


      open XML, "xmlfile.xml";

      $_ = <XML>;


s/<event/#/gm;
s/>\s*</></gm;


my @array = split /#/;


foreach my $element (@array) {
      if  ( $element && $element !~ /<\/event>$/g ) {
            print "FOUND: ";
            print "<event$element\n";
            
      }
};
0
 
LVL 2

Expert Comment

by:scully00000
ID: 9636188
What language are you using? You could use a regex to find the blocks and then search recursively through them for ones missing the </event> tag. Also, what do you want to do with the 'blocks' when you've flagged them? Has a bearing on how the script is written.

Cheers
0
 
LVL 8

Expert Comment

by:fozylet
ID: 9636224
Try your luck at http://www.regexp.org/

A previously answered question there may fit your need.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question