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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:00:01+00:00 2026-05-18T11:00:01+00:00

Ok, so I hate asking RegEx questions because I like to figure them out

  • 0

Ok, so I hate asking RegEx questions because I like to figure them out myself usually. Plus it gets fairly annoying on the other end because people probably ask stupid “why dont you just look it up” questions all the time.

My requirement is simple. I want to use Regex.Replace to replace a Match with a context sensitive value. I use the MatchEvaluator for this. But to make things simpler lets say I’m matching %v

I want %v to be escapable, so if I use \%v it will not match. Anything else should match.

The pattern I came up with is this: (?:[^\\]|^)%v

It basically matches %v if it occurs at the beginning of the string, or if it follows any character except \. It doesn’t capture the first part of the expression.

I know this isn’t the “right” way to do it. But it worked just fine until I noticed that when I use this pattern in a replace, it includes the character before %v in the replacement(duh, right?)

So, if I have ThisIsAValue:%v and I do Regex.Replace, replacing with the string Value, my result will be ThisIsAValueValue instead of ThisIsAValue:Value

I’ve tried googling this but the fact that “escape character” is so heavy in RegEx, all the results are geared towards the USAGE of escape characters instead of picking them out with a pattern.

Any RegEx savvy people know how I can do this correctly?

  • 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-18T11:00:02+00:00Added an answer on May 18, 2026 at 11:00 am

    You can manually put the start character back in, by capturing it and including it in the replace value:

    Regex.Replace("ThisIsAValue:%v", "([^\\]|^)%v", "$1Value")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hate asking questions like this - they're so undefined... and undefinable, but here
i hate asking for help as i would rather figure things for myself, or
I hate Wordpress for numerous reasons, but clients love it because it gives them
I hate asking memory management questions - all the good answers are variations on
Sorry guys, I hate asking dumb questions but I have seriously been searching for
I hate giving out my code like this but I'm getting some errors about
I hate using these because I can never find a tutorial for them. I
Well, I do hate asking vague questions but I can't help it this time:
I hate to admit it but I'm stuck trying to figure out how to
I hate to ask but I've searched all over the internet trying to figure

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.