Solved

parenthesis as memory or substitution?

Posted on 2003-10-22
4
171 Views
Last Modified: 2012-05-04
Please bear with me. I'm a Perl novice.

I have some HTML code being read in from a file with includes this image tag (actually several of them):

<Img Src="/content/Images/Blobs3/bra1master.gif" Width="81" Height="6" Border="0"></Td>

Out of this code, all that I want is the number 81 from the width--nothing else.

How would I go about this?
If I'm not giving enough information let me know, I'll try to be clearer.

0
Comment
Question by:jdixon
  • 2
4 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 50 total points
ID: 9601365
$_ = '<Img Src="/content/Images/Blobs3/bra1master.gif" Width="81" Height="6" Border=""0"></Td>';
($width) = /Width="(\d+)"/;
0
 
LVL 8

Accepted Solution

by:
inq123 earned 250 total points
ID: 9601841
Hi jdixon,

if your img tag is inside normal html file and it's always this syntax, then you probably want to use the whole tag as regex pattern as ozo's solution will get too much noise when a full html file is parsed.  Something like below would work:

while(<IN>) # reading the html file
{
  while(m|<Img\s*Src\s*=\s*"/content/Images/Blobs3/bra1master.gif".*?Width="(\d+)"[^>]*>\s*</Td>|ig)
  {
    print "width is $1\n";
  }
}

This'll be pretty safe since it deals with full html file, it deals with more than one img tag on one line, and it allows for some variations on the img tag.

Cheers!
0
 

Author Comment

by:jdixon
ID: 9602167
Thanks to the both of you! You guys are great not to mention fast.
0
 
LVL 8

Expert Comment

by:inq123
ID: 9602244
You're welcome!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl script help 5 233
Perl Script - Remove row of data based on column value 3 74
use google analytics code in perl script 2 65
Ned Perl Snippet to Read Files in Directory 5 62
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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

13 Experts available now in Live!

Get 1:1 Help Now