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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:21:25+00:00 2026-06-09T04:21:25+00:00

Question 1 I want to match pattern dc_abc and replace with dc_ABC , but

  • 0

Question 1

I want to match pattern dc_abc and replace with dc_ABC, but if the pattern is .dc_abc or "dc_abc", it should remain the same.

Input file:

.dc_abc (dc_abc);
.dc_abc({dc_abc});
dc_abc("dc_abc");

Output_file:

.dc_abc (dc_ABC);
.dc_abc({dc_ABC});
dc_ABC("dc_abc");

Question 2

Is there any way in Perl that I can create two arrays like:

@match_pattern =(!dc_abc , dc_abc: ,dc_abc );
@ignore_pattern = (.dc_abc, {dc_abc});
  • If pattern belongs to @match_pattern, replace it with dc_ABC.
  • If pattern belongs to @ignore pattern, don’t do anything.

Input file:

.dc_abc(dc_abc, {dc_abc});
!dc_abc(!dc_abc);
dc_abc: (dc_abc:);

Output file:

.dc_abc(dc_ABC , {dc_abc});
!dc_abc(dc_ABC);
dc_ABC (dc_ABC);
  • 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-09T04:21:26+00:00Added an answer on June 9, 2026 at 4:21 am

    You can use a negative lookaround to match assertions. You can tell the regular expression that the part you want to match can’t follow a literal dot or quote. The (?<! ) part is the negative lookbehind. Inside that, I have the pattern [."], which is a character class with the characters that can’t precede the rest of the pattern:

    use v5.10;
    
    while( <DATA> ) {
        chomp;
        s/(?<![\."])dc_abc/dc_ABC/g;
        say;
        }
    
    
    __END__
    .dc_abc (dc_abc);
    .dc_abc({dc_abc});
    dc_abc("dc_abc");
    

    This gives:

    .dc_abc (dc_ABC);
    .dc_abc({dc_ABC});
    dc_ABC("dc_abc");
    

    The lookarounds don’t match any characters, and the negative lookbehinds in Perl must be fixed width (so, no quantifiers).

    For question 2, Perl has all the tools you need to do it and leaves it up to you to finish up the logic. I don’t particularly feel like thinking about it this late at night though. Maybe I’ll think of something later. There are various brute force ways to deal with it, but there’s probably something clever.

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

Sidebar

Related Questions

I have a question about the following regular expression: I want to match the
There are actually 2 question i want to cover in this topic. 1) Is
i read the question with a similar title but it doesn't match my problem.
My question is probably simple but I'm a complete newbie. I want to search
From this question How to match this using regex Right now i want to
Following this question it gives me just 1st match. I want to get all
A question out of curiosity, is there a way to do pattern matching on
Question: I want to add a unique constraint on a mapping table (n:n). I
Question: I want code for: syntax highlighting (of programming languages) Language: C# or assembly
Similar Stack Overflow Question I want users to be able to search through my

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.