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

  • Home
  • SEARCH
  • 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 254435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:50:47+00:00 2026-05-11T21:50:47+00:00

How can I remove a substring from a string using Perl? For example, $URL

  • 0

How can I remove a substring from a string using Perl? For example, $URL contains http://xyz.com/Main#abcd.aspx

And I want to check and strip out ‘Main#‘ from $URL Can anyone help me out?

Well first I need to check that whether the string Main# exist or not.
If it exists, then strip it; otherwise nothing needs to be done. So only an if statement.

  • 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-05-11T21:50:47+00:00Added an answer on May 11, 2026 at 9:50 pm

    .

    use strict;
    use warnings;
    use URI::Split qw( uri_split uri_join ); 
    
    my $str = "http://xyz.com/Main#abc.aspx"
    my ($scheme, $auth, $path, $query, $frag)  = uri_split( $str );
    

    That will give you the URI as a series of tokens, but beyond that, the specifics of what you want to do are a bit unclear.

    1. Are you trying to extract the Path so you can use it?
    2. Are you trying to recompose the URI without a path?
    3. Are you trying to extract only a specific node in the path?
    4. Are you trying to recompose the URI without a specific node in the path
    5. Are you trying to filter out only the literal string ‘Main’ , not anything else?

    Well first i need to check that
    whether the string #Main exist or not,
    if it exist then strip it otherwise
    nothing to be done, so only an if
    statement

    if( $str  =~ /#Main/ ){
       $str =~ s/#Main//g;
    }
    

    This will remove the literal string ‘#Main’ from anywhere in the url if it exists. This could also just be written as

    $str =~ s/#Main//g;
    

    Because if it doesn’t exist, no replacements will be done.

    Notable Complications

    If you are trying to retrieve a URI from a web-client, as in, it is a request string, you’ll likely find the #.* part, also known as the document fragment, is already removed from the URI when you get it. This is how in my experience web-clients behave.

    I’m pretty sure there’s an RFC somewhere specifying this to behave like this, but lazyness–

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is NP-hard. (So you should not expect a… May 12, 2026 at 9:28 pm
  • Editorial Team
    Editorial Team added an answer Thanks Kragen, for hinting that beneath the veneer of Explorer's… May 12, 2026 at 9:28 pm
  • Editorial Team
    Editorial Team added an answer It looks like a temporary Gemcutter failure. It works fine… May 12, 2026 at 9:28 pm

Related Questions

I have a string 2500 - SomeValue. How can I remove everything before the
This one has me puzzled. It seemed like an easy task, but the solution
I've got a fairly simple method which recursively removes begining/ending html tags class Program
if I have a string like some/unknown/amount/of/sub/folder/file.txt how can I get only the the

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.