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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:22:47+00:00 2026-06-15T01:22:47+00:00

Consider the following input: BEGINsomeotherstuffEND I’m trying to write a regular expression to replace

  • 0

Consider the following input:
BEGINsomeotherstuffEND

I’m trying to write a regular expression to replace BEGIN and END but only if they both exist.

I got as far as:

(^BEGIN|END$)

Using the following c# code to then perform my string replacement:

private const string Pattern = "(^guid'|'$)";
private static readonly Regex myRegex = new Regex(Pattern, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.Singleline | RegexOptions.IgnoreCase);
var newValue = myRegex.Replace(input, string.empty);

But unfortunately that matches either of those – not only when they both exist.

I also tried:

^BEGIN.+END$

But that captures the entire string and so the whole string will be replaced.

That’s about as far as my Regular Expression knowledge goes.

Help!

  • 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-15T01:22:50+00:00Added an answer on June 15, 2026 at 1:22 am

    How about using this:

    ^BEGIN(.*)END$
    

    And then replace the entire string with just the part that was in-between:

    var match = myRegex.Match(input);
    var newValue = match.Success ? match.Groups(1).Value : input;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider following scenario input string = WIPR.NS i have to replace this with WIPR2.NS
Consider the following mark-up input: * Line 1 * Line 2 :* Line 2.1
Consider the following HTML snipped: <input type=submit value=Delete selected><input type=submit value=Print selected> <div class=table>
Consider the following array as input: $input = array('A', 'B', 'C', 'D'); I'm looking
Consider the following inputs: String[] input = {a9, aa9, a9a9, 99a99a}; What would be
Consider the following code snippet: String input = Print this; System.out.println(input.matches(\\bthis\\b)); Output false What
Consider the following input as an example: [Ami]Song lyrics herp derp [F]song lyrics continue
Background Consider the following input: <Foo Bar=bar Baz=1 Bax=bax > After processing, I need
Consider the following example : <input type=text id=#ab>cd.ef value=foo /> <script type=text/javascript> var id
Consider the following code which takes an integer input and then prints the cin

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.