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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:16:40+00:00 2026-06-11T03:16:40+00:00

I am trying to replace every occurrence of EXECUTE func-name with # EXECUTE func-name.

  • 0

I am trying to replace every occurrence of “EXECUTE func-name” with “# EXECUTE func-name. followed by a hash value” ONLY if the func-name exists. My regex below doesn’t seem to agree with me.

s/EXECUTE ([\w-]+)\.?/"#  EXECUTE $1.\n" . $hash{$1}/eg if (exists($hash{$1}));

Please advise.

  • 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-11T03:16:41+00:00Added an answer on June 11, 2026 at 3:16 am

    Well your code executes the if-condition before the actual regex, so you probably get a warning when executing your code.

    When using the e-modifier you can use perl-code in the “replacement-part” directly:

    s/EXECUTE\s+([\w-]+)\.?/
        if(exists($hash{$1})) {
            "#  EXECUTE $1.\n" . $hash{$1}
        } else {
            $&
        }/xeg;
    

    I have added /x, so you can format the regexp to make it actually readable – but now you have to match the whitespace explicitly (that’s why I’ve added \s+ between EXECUTE and the group). The $& represents the whole match (so if there is no hash-entry for $1, nothing is changed).


    That said, using $& slows down every match and substitution without captures in your entire program. Here’s an improvement:

    s/(EXECUTE\s+([\w-]+)\.?)/
        if(exists($hash{$2})) {
            "#  EXECUTE $2.\n" . $hash{$2}
        } else {
            $1
        }/xeg;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use sed to replace every other occurrence of an html
I'm trying to write a method that does the following: Replace every occurrence of
Hi guys thanks for pay attention to this. Well im trying to replace every
im trying to create a script that opens a file and replace every 'hola'
I'm trying to find every instance of @username in comment text and replace it
I am trying to replace a value with a passed value using javascript or
Lets say I'm trying to replace every A character with a B, inside two
I'm trying to create a function that translates every occurrence of a plain text
I'm trying to replace every image tag in a block of text with a
I'm trying to make a basic replace code that replaces the match every time.

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.