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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:36:51+00:00 2026-06-02T17:36:51+00:00

I am converting some code from Perl into .NET. I have this s/// pattern

  • 0

I am converting some code from Perl into .NET. I have this s/// pattern replacement:

$text =~ s/<A HREF="([^"]+)">\Q\1\E</A>"/$1/gi;

I use the Perl \Q and \E to escape the text I am matching in the first capture, the URL portion of an HREF attribute.

How do I do the same thing in .NET? I’ve read about using Regex.Escape() to escape text for a regular expression, but how can I use it WITHIN the regular expression that is performing the match? (Or do I even need to do that?)

So right now I’m not doing anything special, and wondering if this will continue to work as well as my Perl regex has been:

text = Regex.Replace(text, @"<A HREF=""([^""]+)"">\1</A>", "$1", RegexOptions.IgnoreCase);
  • 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-02T17:36:53+00:00Added an answer on June 2, 2026 at 5:36 pm

    You don’t need the \Q…\E in the Perl. In fact, it will keep your Perl from working, because it means the ‘\1’ is taken literally instead of being replaced with the contents of the first match.

    \Q…\E is for quoting characters that are special in a regex. The string replaced with a backreference is already taken literally, not re-evaluated as regular expression syntax.

    The same goes for anything inserted into the replacement string. You only need \Q…\E, or Regex.Escape(), if you have a variable from outside of regex-land with text that you want to interpolate into a regular expression, without accidentally treating parts of it as a regular expression metacharacters.

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

Sidebar

Related Questions

I am having trouble converting some code from VB6 to VB.NET (I don't have
I have some code that I'm converting from Perl to Java. It makes pretty
I'm converting some c code to python. Can someone convert this for loop from
I have been converting some code from C++ to C#. My lack of understanding
I am converting some code from C# to VB.NET, and I need to know
I currently have some code which grabs some JSON from a site. This is
I'm a C# programmer but am converting some code from C# to VB.NET. In
I am converting some Java code to C#. This code is using getGlyphOutline from
I am manually converting code from Java (1.6) to C# and finding some difficulty
I am in the process of converting some code from C# to Java. I

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.