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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:11:29+00:00 2026-05-14T14:11:29+00:00

This is the input string: 23x^45*y or 2x^2 or y^4*x^3 . I am matching

  • 0

This is the input string: 23x^45*y or 2x^2 or y^4*x^3.

I am matching ^[0-9]+ after letter x. In other words I am matching x followed by ^ followed by numbers. Problem is that I don’t know that I am matching x, it could be any letter that I stored as variable in my char array.

For example:

foreach (char cEle in myarray) // cEle is letter in char array x, y, z, ...
{
    match CEle in regex(input) //PSEUDOCODE
}

I am new to regex and I new that this can be done if I define regex variables, but I don’t know how.

  • 1 1 Answer
  • 1 View
  • 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-14T14:11:30+00:00Added an answer on May 14, 2026 at 2:11 pm

    You can use the pattern @"[cEle]\^\d+" which you can create dynamically from your character array:

    string s = "23x^45*y or 2x^2 or y^4*x^3";
    char[] letters = { 'e', 'x', 'L' };
    string regex = string.Format(@"[{0}]\^\d+",
        Regex.Escape(new string(letters)));
    foreach (Match match in Regex.Matches(s, regex))
        Console.WriteLine(match);
    

    Result:

    x^45
    x^2
    x^3
    

    A few things to note:

    • It is necessary to escape the ^ inside the regular expression otherwise it has a special meaning “start of line”.
    • It is a good idea to use Regex.Escape when inserting literal strings from a user into a regular expression, to avoid that any characters they type get misinterpreted as special characters.
    • This will also match the x from the end of variables with longer names like tax^2. This can be avoided by requiring a word boundary (\b).
    • If you write x^1 as just x then this regular expression will not match it. This can be fixed by using (\^\d+)?.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function like string ToLiteral(string input) from this post . Such that
I'm stuck with regular expression and Java. My input string that looks like this:
Is it possible? This is my input string: ľ š č ť ž ý
I'm developing a perl script. This is my input string in a file new.txt
Given an input string (such as D4C3B2A1) I want to sort the alphabet characters,
Given an input string (will actually be an integer value) and an encryption key,
I have the following input: string txt = i am a string I want
Is there any way to split strings in objective c into arrays? I mean
First, I'm not a regex expert, so I'm pretty sure I'm doing something wrong.
I used http://translate.google.com/#en|hi|Bangalore to get the Hindi for Bangalore and बंगलौर. But when 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.