How to use variables with regex?

Posted by dontoo on Stack Overflow See other posts from Stack Overflow or by dontoo
Published on 2010-04-27T18:57:50Z Indexed on 2010/04/27 19:13 UTC
Read the original article Hit count: 453

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET