scotru
scotru

Reputation: 2606

Equivalent of Substring as a RegularExpression

Ok, I need a general regular expression that will give me the x characters from a string starting at position y like the string's substring function:

input_str.Substring(y,x)

But as a C# regular expression.

Example: 1234567890 Substring(5,3) 678

I know you are thinking why not just use the Substring function? The short answer is because this goes as a data for an existing function and in this context it would be inelegant to create a whole separate data parsing mechanism. We'd like to get this working without changing the code.

I feel like this is really obvious--but I'm pretty inexperienced with regular expressions. Thanks in advance for any help.

Upvotes: 1

Views: 112

Answers (1)

Jeff
Jeff

Reputation: 12785

.{y}(.{x}).* should do it, I think, then just pull out the capture group.

Upvotes: 2

Related Questions