Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 92029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:07:22+00:00 2026-05-10T23:07:22+00:00

I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>

  • 0

I have this input text:

<html><head><meta http-equiv='content-type' content='text/html; charset=utf-8'></head><body><table cellspacing='0' cellpadding='0' border='0' align='center' width='603'>   <tbody><tr>     <td><table cellspacing='0' cellpadding='0' border='0' width='603'>       <tbody><tr>         <td width='314'><img height='61' width='330' src='/Elearning_Platform/dp_templates/dp-template-images/awards-title.jpg' alt='' /></td>         <td width='273'><img height='61' width='273' src='/Elearning_Platform/dp_templates/dp-template-images/awards.jpg' alt='' /></td>       </tr>     </tbody></table></td>   </tr>   <tr>     <td><table cellspacing='0' cellpadding='0' border='0' align='center' width='603'>       <tbody><tr>         <td colspan='3'><img height='45' width='603' src='/Elearning_Platform/dp_templates/dp-template-images/top-bar.gif' alt='' /></td>       </tr>       <tr>         <td background='/Elearning_Platform/dp_templates/dp-template-images/left-bar-bg.gif' width='12'><img height='1' width='12' src='/Elearning_Platform/dp_templates/dp-template-images/left-bar-bg.gif' alt='' /></td>         <td width='580'><p>&nbsp;what y all heard?</p><p>i'm shark oysters.</p>             <p>&nbsp;</p>             <p>&nbsp;</p>             <p>&nbsp;</p>             <p>&nbsp;</p>             <p>&nbsp;</p>             <p>&nbsp;</p></td>         <td background='/Elearning_Platform/dp_templates/dp-template-images/right-bar-bg.gif' width='11'><img height='1' width='11' src='/Elearning_Platform/dp_templates/dp-template-images/right-bar-bg.gif' alt='' /></td>       </tr>       <tr>         <td colspan='3'><img height='31' width='603' src='/Elearning_Platform/dp_templates/dp-template-images/bottom-bar.gif' alt='' /></td>       </tr>     </tbody></table></td>   </tr> </tbody></table> <p>&nbsp;</p></body></html> 

As you can see, there’s no newline in this chunk of HTML text, and I need to look for all image links inside, copy them out to a directory, and change the line inside the text to something like ./images/file_name.

Currently, the Perl code that I’m using looks like this:

my ($old_src,$new_src,$folder_name);     foreach my $record (@readfile) {         ## so the if else case for the url replacement block below will be correct         $old_src = '';         $new_src = '';         if ($record =~ /\<img(.+)/){             if($1=~/src=\'((\w|_|\\|-|\/|\.|:)+)\'/){                 $old_src = $1;                 my @tmp = split(/\/Elearning/,$old_src);                 $new_src = '/media/www/vprimary/Elearning'.$tmp[-1];                 push (@images, $new_src);                 $folder_name = 'images';             }## end if         }         elsif($record =~ /background=\'(.+\.jpg)/){             $old_src = $1;             my @tmp = split(/\/Elearning/,$old_src);             $new_src = '/media/www/vprimary/Elearning'.$tmp[-1];             push (@images, $new_src);             $folder_name = 'images';         }         elsif($record=~/\<iframe(.+)/){             if($1=~/src=\'((\w|_|\\|\?|=|-|\/|\.|:)+)\'/){                 $old_src = $1;                 my @tmp = split(/\/Elearning/,$old_src);                 $new_src = '/media/www/vprimary/Elearning'.$tmp[-1];                 ## remove the ?rand behind the html file name                 if($new_src=~/\?rand/){                     my ($fname,$rand) = split(/\?/,$new_src);                     $new_src = $fname;                     my ($fname,$rand) = split(/\?/,$old_src);                     $old_src = $fname.'\\?'.$rand;                 }         print 'old_src::$old_src\n'; ##s7test         print 'new_src::$new_src\n\n'; ##s7test                 push (@iframes, $new_src);                 $folder_name = 'iframes';             }## end if         }## end if          my $new_record = $record;         if($old_src && $new_src){             $new_record =~ s/$old_src/$new_src/ ;     print 'new_record:$new_record\n'; ##s7test             my @tmp = split(/\//,$new_src);             $new_record =~ s/$new_src/\.\\$folder_name\\$tmp[-1]/; ##  print 'new_record2:$new_record\n\n'; ##s7test         }## end if         print WRITEFILE $new_record;     } # foreach 

This is only sufficient to handle HTML text with newlines in them. I thought only looping the regex statement, but then i would have to change the matching line to some other text.

Do you have any idea if there an elegant Perl way to do this? Or maybe I’m just too dumb to see the obvious way of doing it, plus I know putting global option doesn’t work.

thanks. ~steve

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:07:22+00:00Added an answer on May 10, 2026 at 11:07 pm

    If you must avoid any additional module, like an HTML parser, you could try:

    while ($string =~ m/(?:\<\s*(?:img|iframe)[^\>]+src\s*=\s*\'((?:\w|_|\\|-|\/|\.|:)+)\'|background\s*=\s*\'([^\>]+\.jpg)|\<\s*iframe)/g) {   $old_src = $1;             my @tmp = split(/\/Elearning/,$old_src);                     $new_src = '/media/www/vprimary/Elearning'.$tmp[-1];   if($new_src=~/\?rand/){     // remove rand and push in @iframes   else   {     // push into @images   } } 

    That way, you would apply this regex on all the source (newlines included), and have a more compact code (plus, you would take into account any extra space between attributes and their values)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The best way is by use of a mix between… May 11, 2026 at 7:53 pm
  • Editorial Team
    Editorial Team added an answer Having multiple versions of the same package gets messy (setuptools… May 11, 2026 at 7:53 pm
  • Editorial Team
    Editorial Team added an answer You should probably start with the struct module, as you… May 11, 2026 at 7:53 pm

Related Questions

I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>
I have an input which at some points happens to have the focus. If
I have a website where we use Javascript to submit the login form. On
I am trying to make a form with some dynamic behavior. Specifically, I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.