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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:09:19+00:00 2026-06-01T17:09:19+00:00

I have plain text file ( .txt ) which has some expressions and I

  • 0

I have plain text file (.txt) which has some expressions and I want to replace invalid expression with… …let’s say zero.

An invalid expression is expression which contains 1+3^4^5 or 10+3+4*5+2^5^6^7, i.e. an expression can’t contain number^number^number^..., it can only contain number^number.

I understand that best way to do this is to use Regex but I dont know how to write this in regex.

  • 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-01T17:09:21+00:00Added an answer on June 1, 2026 at 5:09 pm

    The regular expression that will detect multiple powers is

    (\d+\^){2,}
    

    ({2,} means two or more times in a row)


    Just ran the following Test:

    using System;
    using System.Text.RegularExpressions;
    namespace SampleNamespace
    {
        public class SampleClass
        {
            public static void Main()
            {
                string line = "1+3^4^5  10+3+4*5+2^5^6^7";              
                System.Console.WriteLine(line);
                line = Regex.Replace(line, @"(\d+\^){2,}", "0");
                System.Console.WriteLine(line);
            }
        }
    }
    

    Output was:

    >RegexTest.exe
    1+3^4^5  10+3+4*5+2^5^6^7
    1+05  10+3+4*5+07
    

    It failed to replace the trailing \d but it does work. You can grab the trailing \d with the following correction to the regex:

    (\d+\^){2,}\d+
    

    If you want to wipe out the entire expression that contains a double power just use

    .*(\d+\^){2,}.* 
    

    in your replace expresion. The .* on either side will swallow up the entire string surrounding the double power when a replacement takes place.

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

Sidebar

Related Questions

Lets say I have a plain text file example.txt and I have a PHP
I have a plain text document, which I want to compile inside LaTeX. However,
I have a plain text file which have the list of countries as follows.
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
I have two div's one has textbox in it and other just plain text.
Suppose I have something like this: if ($command === 'txt') { header('Content-type: text/plain;charset=utf-8'); echo
Hi I am trying to read a plain text file named test.txt from my
I have a plain text file that I need to read in using C#,
I have files which are just plain text, but have extension which is not
I have a text file that I am pulling from my SD card which

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.