Adding a literal to a regex match

L

Lee Kuhn

Is there a way to add a literal character to a regex match? For example,
normally applying the regex ..$ to the string "123456" results in a match
"56". I want to be to add a literal character to the beginning of the
resultant match string. In other words, is there a regex that could be
applied to the string "123456" to a get a match string "056"?

Thanks.
 
N

Niki Estner

Lee Kuhn said:
Is there a way to add a literal character to a regex match? ...

Yes:
Match m = Regex.Match(...);
string x = "0" + m.ToString();

I guess you somehow wanted to state this 'inside' the regex search pattern.
As the name says it's a search pattern, so, no, you cannot do this.

Niki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top