开发者

Help!!! RegEx.Replace

开发者 https://www.devze.com 2023-01-26 04:27 出处:网络
How do i achieve this directory format using the RegEx. Input File开发者_开发知识库Name(40 chars) : 000a2d0e62e43b0f680a6eb6019f9671b15ca291

How do i achieve this directory format using the RegEx.

Input File开发者_开发知识库Name(40 chars) : 000a2d0e62e43b0f680a6eb6019f9671b15ca291

output should looks like this: 00\0a2\d0e\62e43  
get only the first 13th character.

Thanks a lot.

johnL


What determines a directory names? The length? What happens to everything else? Assuming the first requires 2 characters, second and third requires 3, the last requires 5 and the rest are thrown out, you could do this:

var str = "000a2d0e62e43b0f680a6eb6019f9671b15ca291";
var pattern = @"^(\w{2})(\w{3})(\w{3})(\w{5})";
var output = Regex.Match(str, pattern).Result(@"$1\$2\$3\$4");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号