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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:53:49+00:00 2026-05-18T11:53:49+00:00

I’ve got two question about Regexp::Common qw/URI/ and Regex in Perl. I use Regexp::Common

  • 0

I’ve got two question about Regexp::Common qw/URI/ and Regex in Perl.

I use Regexp::Common qw/URI/ to parse URI in the strings and delete them. But I’ve got an error when a URI is between parentheses.

For example: (http://www.example.com)

The error is caused by ‘)’, and when it try to parse the URI, the app crash. So I’ve thought two fixes:

  • Do a simple (or I thought so) that writes a whitespace between parentheses and ) characters
  • The Regexp::Common qw/URI/ has a function that implement a fix.

In my code I’ve tried to implement the Regex but the app freezes. The code that I’ve tried is this:

use strict;

use Regexp::Common qw/URI/;
my $str = "Hello!!, I love (http://www.example.com)";
while ($str =~ m/\)/){
                $str =~ s/\)/ \)/;
        }
my ($uri) = $str =~ /$RE{URI}{-keep}/;
print "$uri\n";
print $str;

The output that I want is: (http://www.example.com )

I’m not sure, but I think that the problem is in $str =~ s/\)/ \)/;

BTW, I’ve got a question about Regexp::Common qw/URI/. I’ve got two string type:

  1. ablalbalblalblalbal http://www.example.com
  2. asfasdfasdf http://www.example.com aasdfasdfasdf

I want to remove the URI if it is the last component (and save it). And, if not, save it without removing it from the text.

  • 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-18T11:53:50+00:00Added an answer on May 18, 2026 at 11:53 am
    my $str = "Hello!!, I love (GOOGLE)";
    while ($str =~ m/)/){
      $str =~ s/)/ )/;
    }
    

    Your program goes into an infinite loop at this point. To see why, try printing the value of $str each time round the loop.

    my $str = "Hello!!, I love (GOOGLE)";
    while ($str =~ m/)/){
      $str =~ s/)/ )/;
      print $str, "\n";
    }
    

    The first time it prints “Hello!!, I love (GOOGLE )”. The while loop condition is then evaluated again. Your string still matches your regular expression (it still contains a closing parenthesis) so the replacement is run again and this time it prints out “Hello!!, I love (GOOGLE )” with two spaces.

    And so it goes on. Each time round the loop another space is added, but each time you still have a closing parenthesis, so another substitution is run.

    The simplest solution I can see is to only match the closing parenthesis if it is preceded by a non-whitespace character (using \S).

    my $str = "Hello!!, I love (GOOGLE)";
    while ($str =~ m/\S)/){
      $str =~ s/)/ )/;
      print $str, "\n";
    }
    

    In this case the loop is only executed once.

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

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns 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.