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 8280143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:33:46+00:00 2026-06-08T09:33:46+00:00

I’m still learning PERL so any help you could offer would be greatly appreciated.

  • 0

I’m still learning PERL so any help you could offer would be greatly appreciated. I’m sure there is a simple answer to the problem I am looking at, but I’m not sure I can figure it out. Thanks in advance for your help!

I have txt file with a bunch of HTML code in it. There are a number of HTML tables that I want to remove. However, there are a couple that I want to keep. These tables, the keepers, have specific words in them.

Lets say $txt represents the text document

$txt = "<TABLE> The brown dog runs </TABLE> 
        Here is another animal 
        <TABLE> The black cat walks </TABLE> 
        Here is another animal
        <TABLE> The Orange snake slithers </TABLE> 
        Here is another animal   
        <TABLE> Green lizard crawls </TABLE> 
        Here is another animal 
        <TABLE> The brown bird flys </TABLE> 
        Here is another animal          
        <TABLE> The green duck flys </TABLE> 
        Here is another animal";

I want to keep any table that has a brown animal flying animal. I don’t want to keep any of the other tables. (I want to keep the 1st, 5th and 6th tables and get rid of the rest). So keep the table if it has the word brown or if it has the word flys, delete the table if it doesn’t.

I have used the following regular expression to cut out tables in other cases, but this will remove all tables.

$txt =~ s{(<Table>.*?)(</Table>)}{table_was_here}ismog;

How could i modify this code to keep tables that contain certain text strings?

Thanks again!

  • 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. Editorial Team
    Editorial Team
    2026-06-08T09:33:49+00:00Added an answer on June 8, 2026 at 9:33 am

    Both of the following will work:

    $txt =~ s{<TABLE>.*?</TABLE>}{$_ = $&; /brown|flys/ ? $_ : ''}isge;
    
    for ( $txt =~ m{<TABLE>.*?</TABLE>}isg ) {
        $txt =~ s/$_// if !/brown|flys/;
    }
    

    Output of both:

    <TABLE> The brown dog runs </TABLE> 
    Here is another animal 
    
    Here is another animal
    
    Here is another animal   
    
    Here is another animal 
    <TABLE> The brown bird flys </TABLE> 
    Here is another animal          
    <TABLE> The green duck flys </TABLE> 
    Here is another animal
    

    Hope this helps!

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
This could be a duplicate question, but I have no idea what search terms

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.