I would suggest you change your approach and user the query mode of RPM to get your information instead of build up a regexp:
rpm -qa --queryformat "%{NAME}\n" Duncs From: Asad [mailto:asad.hasan2...@gmail.com] Sent: 27 July 2018 13:55 To: beginners@perl.org Subject: regex to get the rpm name version Hi All , I want to get a regex to actually get the rpm name and version for comparison : binutils-2.23.52.0.1-12.el7.x86_64", compat-libcap1-1.10-3.el7.x86_64" compat-libstdc++-33-3.2.3-71.el7.i686 (^[a-zA-Z0-9\-]*)\-\d' First part of the regular expression is ^[a-zA-Z0-9\-] which means search for anything that begins with a letter (lower or upper) or a number up until you reach an hyphen sign (‘-‘). but it fails to match compat-libstdc++-33-3.2.3-71.el7.i686 Please let me know what regex should i use to extract all 3 rpms. Also let me know if there are web tools to build regex Good websites for regex tutorials. Thanks, -- Asad Hasan +91 9582111698