Solved

parenthesis as memory or substitution?

Posted on 2003-10-22
4
163 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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 …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

15 Experts available now in Live!

Get 1:1 Help Now