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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:13:07+00:00 2026-05-30T03:13:07+00:00

I am doing a file search and replace for occurrences of specific words in

  • 0

I am doing a file search and replace for occurrences of specific words in perl. I’m not usually much of a perl or regex user. I have searched for other regex questions here but I couldn’t find one which was quite right so I’m asking for help. My search and replace currently looks like this:

s/originalword/originalword_suffix/g

This matches cases of originalword that appear in the middle of another word, which I don’t want. In my application of search and replace, a whole word can be defined as having the letters of the latin alphabet in lowercase or capital letters and the digits 0-9 and the symbol _ in any uninterrupted sequence. Anything else besides these characters, including any other symbols or any form of whitespace including line breaks or tabs, indicate operations or separators of some kind so they are outside the word boundaries. How do I modify my search and replace to only match whole words as I’ve defined them, without matching substrings?

Examples:

in the case that originalword = cat and originalword_suffix = cat_tastic

:cat { --> :cat_tastic {
:catalog { --> no change
  • 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-30T03:13:09+00:00Added an answer on May 30, 2026 at 3:13 am

    Use the \b anchor to match only on a word boundary:

    s/\bcat\b/cat_tastic/g
    

    Although Perl has a slightly different definition of what a “word” is. Reading the perlre reference guide a couple of times might help you understand regexps a bit better.

    Running perl -pi -e “YOUR_REGEXP” in a terminal and entering in lines of text can help you understand and debug what a particular regexp is doing.

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

Sidebar

Related Questions

I have used file search functionality in eclipse to replace a specific occurrence of
I have a perl script (or any executable) E which will take a file
I'm doing a file search, and I want to exclude files that contain min
I am doing some research where I have +25,000 reports in one large text-file.
I have a Google Instant style jQuery search script that queries a PHP file
I've searched long and hard for an answer to doing this & have come
So the jist of this is, I have a file: search.php When I goto:
I have found a XML file through google search that will help me for
I have an autofill search that reads the contents of a text file (this
I have a search query from the user and I want to process it

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.