Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Search pattern from end of line

by asab (Sexton)
on Nov 25, 2010 at 06:00 UTC ( [id://873580] : perlquestion . print w/replies, xml ) Need Help??

asab has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I need a perl reg-expression which extracts the pattern as below.

Basically we want to parse and extract the rpms from the packages.xml inside RHEL cd hence looking for a pattern which extracts the contents between >xyz</rpm>.

Note there might be any set of character/white space before > symbol but all the lines ends with </rpm> pattern.

Any help with regard to this is of great help.

Eg:
<rpm>acl-2.2.39-3.el5.x86_64.rpm</rpm> <rpm>acpid-1.0.4-9.el5_4.2.x86_64.rpm</rpm> <rpm>attr-2.4.32-1.1.x86_64.rpm</rpm> <rpm>audispd-plugins-1.7.13-2.el5.x86_64.rpm</rpm> <rpm>audit-1.7.13-2.el5.x86_64.rpm</rpm> <rpm>audit-libs-python-1.7.13-2.el5.x86_64.rpm</rpm> <rpm>basesystem-8.0-5.1.1.noarch.rpm</rpm> <rpm>libtermcap-2.0.8-46.1.x86_64.rpm</rpm> <rpm>bash-3.2-21.el5.x86_64.rpm</rpm> <rpm component="pamperuser04_rhel52_32" package="pam-per-user- +0.4">pam_per_user-0.4-2053.vmw.i686.rpm</rpm> <rpm component="libusb0112_rhel52_32" package="libusb-0.1.12"> +libusb-0.1.12-5.1.2053.vmw.i686.rpm</rpm> <rpm component="usbutils071_rhel52_32" package="usbutils-0.71" +>usbutils-0.71-2.1.2073.vmw.i686.rpm</rpm> <rpm component="libidn065_rhel52_32" package="libidn-0.6.5">li +bidn-0.6.5-1.1.2053.vmw.i686.rpm</rpm>

Thanks in advance

asab

Replies are listed 'Best First'.
Re: Search pattern from end of line
by lidden (Curate) on Nov 25, 2010 at 06:30 UTC
    my ($rpm) = $line =~ />([^>]+)</rpm>\s*$/;
      Thanks a lot.This is the one that i was looking for. asab
Re: Search pattern from end of line
by Anonymous Monk on Nov 25, 2010 at 06:19 UTC

      I guess use XML::Parser; wont be that useful as the pattern before initial > in the pattern >xyz</rpm> varies considerably.

      can any one gives a regular expression for this. Thanks asab
        I guess use XML::Parser; wont be that useful as the pattern before initial

        That won't make a bit of difference. XML::Simple is simpler than XML::Parser