C# regex. Optional match after string
Posted
by Oskar Kjellin
on Stack Overflow
See other posts from Stack Overflow
or by Oskar Kjellin
Published on 2010-05-14T13:49:16Z
Indexed on
2010/05/14
13:54 UTC
Read the original article
Hit count: 885
I have an input like this test1.test2.part01
which I want to strip away to test1.test2
. The only thing i know is that it will end with partxx
and probably a dot before the partxx
. However, it will not always be a apart. Another example of input might be testas1.tlp2.asd3.part10
which ofcourse should be stripped to testas1.tlp2.asd3
.
I've made all that, no problem. The problem is the dot at the end before partxx
. My regex at the moment is:
(.*).?part\d{1,2}
But it will include the dot in the group. I do not want the dot to be in the group. The below works as I want it, given that the dot exists, but it will not always be there.
(.*).part\d{1,2}
How can I exclude the optional dot from the group?
© Stack Overflow or respective owner