Perl Regular Expression avoiding special characters

Posted on 2007-09-28
Medium Priority
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 85

Accepted Solution

ozo earned 500 total points
ID: 19983170
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

ID: 19983586
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans
Suggested Courses

840 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