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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:15:26+00:00 2026-06-12T08:15:26+00:00

I am using regex to replace certain keywords from a string (or Stringbuilder) with

  • 0

I am using regex to replace certain keywords from a string (or Stringbuilder) with the ones that I choose. However, I fail to build a valid regex pattern to replace only whole words.

For example, if I have InputString = “fox foxy” and want to replace “fox” with “dog” it the output would be “dog dogy”.

What is the valid RegEx pattern to take only “fox” and leave “foxy”?

 public string Replace(string KeywordToReplace, string Replacement) /
        {

            this.Replacement = Replacement;
            this.KeywordToReplace = KeywordToReplace;

            Regex RegExHelper = new Regex(KeywordToReplace, RegexOptions.IgnoreCase);

            string Output = RegExHelper.Replace(InputString, Replacement);

            return Output;
        }

Thanks!

  • 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-12T08:15:28+00:00Added an answer on June 12, 2026 at 8:15 am

    Regexes support a special escape sequence that represents a word boundary. Word-characters are everything in [a-zA-Z0-9]. So a word-boundary is between any character that belongs in this group and a character that doesn’t. The escape sequence is \b:

    \bfox\b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible using Regex.Replace to match a string, but only replace a portion
I'm looking for a regex that will find and replace certain patterns in a
I am using a regex to replace all email addresses in a string with
Is there a way using regex to replace characters in a string based on
i'm having a string var str = hello -- (world); using regex and replace
I have am using regex.replace to replace a '#' character with a Environment.Newline. However
I am removing all non-numeric and non-decimal values using: Regex.Replace(A1B2C3.D4E5F6.G7H8I9, @[^-?\d+\.], ); Output: 123.456.789
I am having an issue where I am using regex.Replace to replace part of
I'm using regEx and replace method to replace an empty space with a dash
I'm using the regex System.Text.RegularExpressions.Regex.Replace(stringToSplit, ([A-Z]), $1).Trim() to split strings by capital letter, for

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.