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,530 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
XSL Grouping 7 43
css border raidius issue 7 97
How to silent print from safari browser 6 315
The Best Website Creation Tools 14 122
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

737 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