Paired Tags


OK, enough advertising. Let s do another test.

In XML, tags must always be paired and properly nested, unlike HTML, which is more liberal . So in a legal paragraph in XML, we have a leading <p> and a trailing </p>. We ll write a test to see if we can recognize such a string.

 [Test] public void PairedParagraphs() { 
Regex r = new Regex("<p>.*</p>");
Match m = r.Match("<p>this is a para</p>");
Assert(m.Success);
}

So there we are. The Regex looks for a p tag, an un-p tag, as I call them, and anything in between. (In Regex, dot means any character, and star means any number of the preceding . ) Again, we get the green bar. I m having good luck so far, maybe because I ve done some stuff with regular expressions in Ruby and read most of the famous regular expressions book, Mastering Regular Expressions , by Jeffrey E. F. Friedl (O Reilly & Associates, 2002). The next problem, though, gets a bit trickier, and as we ll see, I have some problems with it.




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net