Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2011, 03:05 AM
Registered User
 
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pattern Matching with Regular Expressions in perl

Hi

i have doubts in Pattern Matching with Regular Expressions in perl,


input:

sample.xml
----------

<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" article-type="">
<front>
<publisher>
<publisher-name>Public Library of Science</publisher-name>
</publisher>
</article>


perl coding:
-----------

if ($line=~m/<publisher>\s*<publisher-name>(.*)<\/publisher-name>/gi)
{
$colno = pos ($line);
push @errors, "[$lineno:$colno]\t--publisher name: \"$1\" \n";
}


output:
--------

Sample.xml
Below are the 0 Notification(s) Found:-
--------------------------------------



My expecting output
------------------

Sample.xml
Below are the 1 Notification(s) Found:-
--------------------------------------

[3:69] --publisher name: "Public Library of Science"



Pls reply

Thanks in Advance

Sankar B
 
Old February 26th, 2011, 07:28 AM
Authorized User
 
Join Date: Aug 2009
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Default

In this case you need /s regex modifier, but you will have problems with parsing XML with regexes. Use XML parsing module like XML::Twig.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expressions and string matching DennyLoi Java Basics 0 November 15th, 2007 01:37 PM
Regular expression to select non-matching pattern Neuron BOOK: Beginning Regular Expressions 1 June 12th, 2006 10:06 AM
PHP Pattern Matching joanncae BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 May 17th, 2004 04:52 PM
Pattern Matching using PHP spraveens PHP Databases 2 March 23rd, 2004 10:03 PM
perl compatible regular expressions richard.york Pro PHP 5 November 6th, 2003 04:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.