Perl Regular Expression avoiding special characters

Posted on 2007-09-28
Last Modified: 2012-08-13
I am writing a perl script which is parsing a file into an array and then going through the array line by line.  I then need to grab every instance where there is a label.  For instance the following will both be in the file:
1) label1234.Text

I need to be able to catch case #1 and avoid case #2.  I am ultimately just trying to grab the number after label as $1 for all case 1s.

This is what I am trying and it is not working:
if ( $playarray[$x] =~ m/[^\/\/]/g ) {
            if ( $playarray[$x] =~ m/label(.*?).Text/g ) {
                  print FILE "<asp:Label ID=\"Label".$1."\" runat=\"server\" Text=\"Label".$1."\" Width=\"57px\"></asp:Label>\n";
                  $temp = 2;

The intent was that the first if statement would would avoid anything that had // and the second if statement would then grab my case #1.  This is not working.  Any thoughts?

Question by:spoma
    LVL 84

    Accepted Solution

    print FILE  qq(<asp:Label ID="Label$1" runat="server" Text="Label$1" Width="57px"></asp:Label>\n) if $playarray[$x] =~ m((?<!//)label(.*?)\.Text);

    Author Comment

    perfect.  thanks.  That gets credit.  Any chance you could explain that expression to me so i understand it a little better for future projects?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now