Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

parenthesis as memory or substitution?

Posted on 2003-10-22
4
Medium Priority
?
210 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 85

Assisted Solution

by:ozo
ozo earned 200 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans

886 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