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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:02:26+00:00 2026-05-16T07:02:26+00:00

I need a regular expression to uncomment a block of Perl code, commented with

  • 0

I need a regular expression to uncomment a block of Perl code, commented with # in each line.

As of now, my find expression in the Eclipse IDE is (^#(.*$\R)+) which matches the commented block, but if I give $2 as the replace expression, it only prints the last matched line. How do I remove the # while replacing?

For example, I need to convert:

# print "yes";
# print "no";
# print "blah";

to

print "yes";
print "no";
print "blah";
  • 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-16T07:02:27+00:00Added an answer on May 16, 2026 at 7:02 am

    In most flavors, when a capturing group is repeated, only the last capture is kept. Your original pattern uses + repetition to match multiple lines of comments, but group 2 can only keep what was captured in the last match from the last line. This is the source of your problem.

    To fix this, you can remove the outer repetition, so you match and replace one line at a time. Perhaps the simplest pattern to do this is to match:

    ^#\s*
    

    And replace with the empty string.

    Since this performs match and replacement one line at a time, you must repeat it as many times as necessary (in some flavors, you can use the g global flag, in e.g. Java there are replaceFirst/All pair of methods instead).

    References

    • regular-expressions.info/Repeating a Captured Group vs Capturing a Repeated Group

    Related questions

    • Is there a regex flavor that allows me to count the number of repetitions matched by * and +?
      • .NET regex keeps all repeated matches

    Special note on Eclipse keyboard shortcuts

    It Java mode, Eclipse already has keyboard shortcuts to add/remove/toggle block comments. By default, Ctrl+/ binds to the “Toggle comment” action. You can highlight multiple lines, and hit Ctrl+/ to toggle block comments (i.e. //) on and off.

    You can hit Ctrl+Shift+L to see a list of all keyboard shortcuts. There may be one in Perl mode to toggle Perl block comments #.

    Related questions

    • What is your favorite hot-key in Eclipse?
    • Hidden features of Eclipse
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an regular expression which matches the following: 'test foo bar, test' =>
I need a regular expression which matches: http://example.com/foo http://example.com/foo/ http://example.com/foo/bar but not: http://example.com/foobar Using
I need a regular expression to find out whether or not a h1 tag
Need single regular expression for finding double spaces tabs extra enter (line-break/carriage return) line
I need a regular expression that can find any unmatched brace (opening or closing)
I need regular Expression which should start with letters only and later it can
I need a regular expression to find a number in the range [40010-40100]. I
I need a regular expression which matches contains all words then a space and
I need regular expression that matches a pattern or is empty. Right now I
Need a regular expression to validate username which: should allow trailing spaces but not

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.