Thursday, 15 May 2014

Regex neglect Pattern in C# -



Regex neglect Pattern in C# -

i delete matches result(blue area) form file name remove strings want delete "part " , " " , leave numbers in reddish area, how can accomplish pattern?

use next regex:

-part-\d+|^part\s+|(?<=^part\s+\d+)\s+

sample code:

string[] input = { "102redirect-http-to-https-in-iis-part-102.mp4", "4events-in-the-life-cycle-of-a-web-application-part-4.mp4", "part 5 menu command in asp net.mp4", "part 153 menu command in asp net.mp4" }; string[] output = input.select(s => regex.replace(s, @"-part-\d+|^part\s+|(?<=^part\s+\d+)\s+", string.empty)) .toarray(); foreach (string s in output) console.writeline(s);

output:

102redirect-http-to-https-in-iis.mp4 4events-in-the-life-cycle-of-a-web-application.mp4 5menu command in asp net.mp4 153menu command in asp net.mp4

c# regex

No comments:

Post a Comment